Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support lazy refreshing of long-lived cache entries #467

Open
adamhoward56 opened this issue Dec 4, 2024 · 0 comments
Open

Support lazy refreshing of long-lived cache entries #467

adamhoward56 opened this issue Dec 4, 2024 · 0 comments

Comments

@adamhoward56
Copy link

adamhoward56 commented Dec 4, 2024

Hey team!

I have a use case where my cache expires entries hours after being written. I would like to lazily refresh these values to prevent staleness, i.e. if I retrieve an entry older than a few minutes, Moka will yield the stale value but also kick off a background process to compute the latest value.

The desired behavior would be adjacent to Guava's LoadingCache refreshAfterWrite functionality:

refreshAfterWrite will make a key eligible for refresh after the specified duration, but a refresh will only be actually initiated when the entry is queried.

Callers would need to provide (1) a function that Moka executes in the background to compute the latest cache value and (2) a parameter to define a staleness threshold after which a refresh should be performed.

It's easy to write a small wrapper that implements this behavior, but perhaps it would be more widely beneficial to include support for this directly in Moka. Curious if this could be considered/added to the roadmap, thanks!

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

No branches or pull requests

1 participant