Skip to content

Keep owner directory searches fresh after record changes - #3

Open
ivanmilevtues wants to merge 3 commits into
mainfrom
feature/owner-search-cache-coherence
Open

Keep owner directory searches fresh after record changes#3
ivanmilevtues wants to merge 3 commits into
mainfrom
feature/owner-search-cache-coherence

Conversation

@ivanmilevtues

Copy link
Copy Markdown
Member

Summary

  • cache paginated owner-directory searches for faster front-desk lookups
  • invalidate cached owner results after owner, pet, and visit mutations
  • add operational endpoints for checking and manually refreshing the owner-search cache
  • keep the existing veterinarian cache behavior unchanged

Why

Front-desk searches can otherwise return stale owner aggregates after contact details, pets, or visits change. Centralizing cache operations gives support staff a direct diagnostic path while ensuring every owner aggregate mutation refreshes subsequent searches.

Validation

  • ./mvnw test
  • 81 tests passed
  • Spring Java Format and Checkstyle passed

Architecture note

Owner aggregate mutation handling now calls the cache operations boundary directly so search consistency is enforced synchronously.

@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown

CodeBoarding review

Status: 6 changed components

See the full change in CodeBoarding.

graph LR
    n_Owner_and_Pet_Management["Owner and Pet Management"]
    n_Veterinarian_Management["Veterinarian Management"]
    n_Web_Presentation_and_Localization["Web Presentation and Localization"]
    n_Cache_Configuration_and_Diagnostics["Cache Configuration and Diagnostics"]
    n_Application_Bootstrap["Application Bootstrap"]
    n_Owner_and_Pet_Management -- "invalidates search cache on aggregate updates" --> n_Cache_Configuration_and_Diagnostics
    n_Veterinarian_Management -- "relies on cache configuration for query caching" --> n_Cache_Configuration_and_Diagnostics
    n_Web_Presentation_and_Localization -- "intercepts web requests for locale switching" --> n_Owner_and_Pet_Management
    n_Web_Presentation_and_Localization -- "intercepts web requests for locale switching" --> n_Veterinarian_Management
    n_Application_Bootstrap -- "registers AOT runtime hints for core domain ent…" --> n_Owner_and_Pet_Management
    n_Application_Bootstrap -- "Bootstraps and registers veterinarian controlle…" --> n_Veterinarian_Management
    n_Application_Bootstrap -- "Registers web configuration and landing page en…" --> n_Web_Presentation_and_Localization
    n_Application_Bootstrap -- "Initializes cache subsystem and diagnostic cont…" --> n_Cache_Configuration_and_Diagnostics
    classDef added fill:#1f883d,stroke:#0b5d23,color:#ffffff;
    classDef modified fill:#bf8700,stroke:#7d4e00,color:#ffffff;
    classDef deleted fill:#cf222e,stroke:#82071e,color:#ffffff,stroke-dasharray:5 3;
    class n_Owner_and_Pet_Management,n_Web_Presentation_and_Localization,n_Cache_Configuration_and_Diagnostics modified;
    linkStyle 0 stroke:#0b5d23,stroke-width:2px;
    linkStyle 1,2,3,4 stroke:#7d4e00,stroke-width:2px;
    linkStyle 6,7 stroke:#82071e,stroke-width:2px,stroke-dasharray:5 3;
Loading

download artifacts · run 33027898375

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df1c58481e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

* @return a Collection of matching {@link Owner}s (or an empty Collection if none
* found)
*/
@Cacheable(CacheOperations.OWNER_SEARCH_CACHE)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Bound the owner-search cache

Each distinct (lastName, Pageable) supplied to GET /owners now creates a permanent cache entry, but the configured Caffeine cache has neither a maximum size nor an expiry policy. Because every entry retains a full page of eager owner/pet/visit aggregates, ordinary varied searches—or requests deliberately using unique search strings and page numbers—can grow the heap without bound until the application is restarted or the entire cache is manually cleared. Configure an eviction limit/TTL or restrict which searches are cached.

Useful? React with 👍 / 👎.

if (cache == null) {
return false;
}
cache.clear();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Prevent stale searches from repopulating after eviction

When a cache-miss search overlaps a mutation, the search can read the old database state, the mutation can commit and execute this clear, and the search's @Cacheable interceptor can then publish its old Page after the clear has completed. That stale result remains indefinitely because the cache has no expiry and no further invalidation is guaranteed, so the synchronous clear does not actually ensure fresh searches under concurrent requests. Use a generation/versioned key or otherwise coordinate cache population with writes.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant