Skip to content

Setting both expireAfterAccess and expireAfterWrite policies as they're no mutually exclusive #511

Answered by ben-manes
kvajjala59 asked this question in Q&A
Discussion options

You must be logged in to vote

I don't recommend using both, as it is a quirk in Guava that we mirror for compatibility (and perhaps should not have). You can use expireAfter(expiry) instead.

The two timestamps are maintained independently, so it is whatever has the shortest duration. expireAfterAccess will update its timestamp on every read or write, so it depends on which fixed duration is smaller. If 30s access and 5 min write, then absent of writes the access policy will evict. If the access duration is equal or greater, then the write policy will be dominant if only reads occur. I don't think there is a use-case that benefits by having both enabled.

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@kvajjala59
Comment options

@WChrisGraham
Comment options

@ben-manes
Comment options

Answer selected by kvajjala59
Comment options

You must be logged in to vote
1 reply
@ben-manes
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants