Skip to content

I'm curious about the impact of using a Scheduler when creating a Caffeine cache. #1823

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

You must be logged in to vote

It doesn’t look like you need the scheduler. By default the various activity on the cache will cause it to periodically evict expired entries. That could mean an idle cache won’t evict for a while. When a listener is attached, sometimes there is a desire to promptly notify upon expiration instead of waiting. The scheduler has the next expiration event for its delay so that it can trigger the cleanup. An example might be to disconnect idle users after a session timeout (expireAfterAccess). If you don’t use a listener or need percise eviction timings, then you can skip it and piggyback on regular activity.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jojaeng2
Comment options

@ben-manes
Comment options

Answer selected by ben-manes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants