Skip to content

Keep owner directory searches fresh after record changes - #3

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

ivanmilevtues wants to merge 4 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: 4 changed components

See the full change in CodeBoarding.

graph LR
    n_owner["owner"]
    n_vet["vet"]
    n_system["system"]
    n_model["model"]
    n_Loose_files_in_src_main_java_org_springframework_samples_petclinic["Loose files in src.main.java.org.springframework.samples.petclinic"]
    n_owner -- "calls" --> n_system
    n_owner -- "calls" --> n_model
    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,n_system modified;
    linkStyle 0 stroke:#0b5d23,stroke-width:2px;
Loading

download artifacts · run 35936848401

@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