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

Expire after time and a succesful retrieval #501

Closed
aschuhl opened this issue Feb 11, 2021 · 5 comments
Closed

Expire after time and a succesful retrieval #501

aschuhl opened this issue Feb 11, 2021 · 5 comments

Comments

@aschuhl
Copy link

aschuhl commented Feb 11, 2021

So currently we are using caffeine to store an item for 2 minutes very successfully.

Our implementation is basically:

 return cache.get(
       cacheKey, k -> retrieveSchema());
 }

We had an issue where the service retrieveSchema calls failed, so we no longer had the item. So I am wondering is there a way to set it so it won't expire until 2 minutes after creation and another retrieval occurs? We would rather use a more stale schema then no schema, so wondering if this is possible.

@ben-manes
Copy link
Owner

I'm not sure that I follow.

Expiration is a hard cutoff for when an entry can no longer be used because its data may be too old (e.g. freshness, inactivity). The cache can then discard it to reclaim space.

Refresh might be more appropriate. This will return the existing value but, if it is older than the duration, a reload will occur asynchronously. That hides latency by not penalizing the caller with the load. When combined with expiration, the refresh keeps active content fresh and inactive content is discarded automatically. These rules are time-based.

Would refresh serve your needs?

@ben-manes
Copy link
Owner

Closing due to lack of clarification.

@aschuhl
Copy link
Author

aschuhl commented Feb 22, 2021

Sorry about that Ben, but refresh looks exactly what we need. Thank you!

@aschuhl
Copy link
Author

aschuhl commented Mar 16, 2021

@ben-manes Looking into this a little further, I noticed there is not a similar api as new Expiry() to create a custom expiration. We have our data in two different states, that we would like to refresh at a different times. This is possible with eviction, but doesn't seem possible with refresh unless I am missing something. Is my understanding correct?

@ben-manes
Copy link
Owner

ben-manes commented Mar 16, 2021

Unfortunately that is not supported yet. The feature is described in #504 but no work has started yet.

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

2 participants