Setting both expireAfterAccess and expireAfterWrite policies as they're no mutually exclusive #511
-
What is the behavior when we set both eviction policies expireAfterAccess and expireAfterWrite? Which does take preference? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
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 The two timestamps are maintained independently, so it is whatever has the shortest duration. |
Beta Was this translation helpful? Give feedback.
-
What about the case where you want to evict unused entries after 1 day and all entries 3 days after they were written regardless of when they were last accessed? IE, you want to make sure nothing cached is older than 3 days so it's not too stale. |
Beta Was this translation helpful? Give feedback.
-
Makes sense! Thanks for the clarification. |
Beta Was this translation helpful? Give feedback.
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.