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

Is there any way to access the value without reseting its access time #413

Closed
shuodashen opened this issue Apr 28, 2020 · 3 comments
Closed

Comments

@shuodashen
Copy link

Both following methods will reset the access time of the "key"
cache.getIfPresent("key"); cache.asMap().get("key");

We have set a duration of "expireAfterAccess", and on some special conditions, we want to get the cache, but do not reset its access time.

@shuodashen
Copy link
Author

I think I have got the answer: #229

@ben-manes
Copy link
Owner

ben-manes commented Apr 28, 2020

Ahh, I forgot about that one. Yes, the semantics becomes very confusing as to how quiet a method is.

For your case, the simplest workaround would probably require switching to expireAfter(Expiry). This would allow you to specify a custom strategy for determining the entry's remaining lifetime. A thread-local could capture that the duration shouldn't change and the prior value be returned. By setting the flag before the cache lookup, you could instruct your routine whether to reset the time or not.

@ben-manes
Copy link
Owner

Released 2.8.3 which includes cache.policy().getIfPresentQuietly(key) which skips updating any cache metadata.

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