ben-manes / caffeine

A high performance caching library for Java
Apache License 2.0
15.64k stars 1.58k forks source link

Get the least recent used key-value #1727

Closed Aitozi closed 2 months ago

Aitozi commented 2 months ago

Can we retrieve the least recently used key-value pair from the cache that is about to expire?

I want to use Caffeine as a memory map for values stored on disk. When the capacity is reached, I need to identify the next key-value pair set to expire and determine which value will free up space for storing new data on disk.

ben-manes commented 2 months ago

Yes, see cache.policy(). The expiration policy can return what it thinks are the oldest (next to expire) and the eviction policy the coldest (least recently/frequently used).