Class CaffeineExpiringCache
-
- All Implemented Interfaces:
public class CaffeineExpiringCache<K extends Object, V extends Object>A Caffeine-backed alternative to ai.platon.pulsar.common.concurrent.ConcurrentExpiringLRUCache that exposes the same
putDatum/getDatum/remove/clear/sizeAPI for drop-in compatibility.Entries are evicted via Caffeine's Window TinyLFU policy when the cache exceeds capacity, and expire after ttl regardless of access.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classCaffeineExpiringCache.EntryLightweight entry wrapper so that remove can return the removed value via
.datum, matching the ConcurrentExpiringLRUCache contract.public classCaffeineExpiringCache.Companion
-
Field Summary
Fields Modifier and Type Field Description public final static LongDEFAULT_CAPACITYprivate final Longsizepublic final static CaffeineExpiringCache.CompanionCompanion
-
Constructor Summary
Constructors Constructor Description CaffeineExpiringCache(Duration ttl, Long capacity)
-
Method Summary
Modifier and Type Method Description final LonggetSize()final UnitputDatum(K key, V value)Cache an item. final VgetDatum(K key)Retrieve a non-expired item (Caffeine handles time-based expiry automatically). final VgetDatum(K key, Duration expires, Instant now)Retrieve an item with an additional caller-specified expiry window. final CaffeineExpiringCache.Entry<V>remove(K key)Remove and return the cached entry. final Unitclear()Remove all entries. final Cache<K, CaffeineExpiringCache.Entry<V>>asCache()Underlying Caffeine cache for direct access when needed. final CacheStatsstats()-
-
Method Detail
-
getDatum
final V getDatum(K key)
Retrieve a non-expired item (Caffeine handles time-based expiry automatically).
-
getDatum
final V getDatum(K key, Duration expires, Instant now)
Retrieve an item with an additional caller-specified expiry window.
Caffeine already expires entries based on the cache-level TTL, but callers may pass a tighter expires duration + now to reject entries that are technically in the cache but older than the caller's threshold.
NOTE: The caller is responsible for checking the returned value's own timestamp (e.g. ai.platon.pulsar.persist.WebPage.prevFetchTime) via
options.isExpired().
-
remove
final CaffeineExpiringCache.Entry<V> remove(K key)
Remove and return the cached entry.
- Returns:
the removed Entry (with its Entry.datum), or null if the key was not present.
-
asCache
final Cache<K, CaffeineExpiringCache.Entry<V>> asCache()
Underlying Caffeine cache for direct access when needed.
-
stats
final CacheStats stats()
-
-
-
-