-
Hi, I am currently considering using Caffeine as follows: centerAuthCaches = Caffeine.newBuilder()
.expireAfterWrite(Duration.ofSeconds(10L))
.refreshAfterWrite(Duration.ofSeconds(5L))
.scheduler(Scheduler.systemScheduler())
.buildAsync((key, executor) -> mappingFunction(key)); I have reviewed the expireAfterWrite and refreshAfterWrite options, but I have some questions about the Scheduler. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
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. |
Beta Was this translation helpful? Give feedback.
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.