Skip to content

What routine maintenance are carried out when cache is expired? #524

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

You must be logged in to vote

In a single threaded cache, one could perform housekeeping work on every request. For example reorder on an LRU for size eviction, check if an expiration occurred, or peek at the ReferenceQueue if a weak/soft entry was collected. These operations are fast but not friendly for concurrency, e.g. an LRU is a doubly-linked list where the entry is moved to the tail (many non-atomic pointer changes). A traditional cache like LinkedHashMap required synchronization, but at high concurrency the locking is more expensive than the policy maintenance.

Caffeine instead performs this policy work periodically. It captures events like reads and writes into a small queue (ring buffers), which are cheap to…

Replies: 1 comment 3 replies

Comment options

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

@ben-manes
Comment options

@Oluwatobiadeoye
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