Package dev.relism.flash.ext.cache
Class CacheSpec
java.lang.Object
dev.relism.flash.ext.cache.CacheSpec
How one cache should behave. Every field is optional — a spec that sets nothing gives an
unbounded cache that never expires, which is a memory leak wearing a hat, so set at least one
of
maxSize or ttl.
CacheSpec.of().maxSize(10_000).ttl(Duration.ofMinutes(10))
Mutable builder rather than a record with withX copies: it is constructed once at
boot inside a lambda and never shared.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanbounded()longmaxSize()maxSize(long maxSize) Maximum entries before the backend starts evicting.static CacheSpecof()Records hit/miss counters forCache.stats().booleanttl()Entries expire this long after they were written.ttlAfterAccess(Duration ttlAfterAccess) Entries expire this long after they were last read or written.
-
Method Details
-
of
-
maxSize
Maximum entries before the backend starts evicting. Negative means unbounded. -
ttl
Entries expire this long after they were written. -
ttlAfterAccess
Entries expire this long after they were last read or written. -
recordStats
Records hit/miss counters forCache.stats().Off by default: counting costs a pair of atomic increments on every lookup, and a cache nobody is measuring should not pay for numbers nobody reads.
-
maxSize
public long maxSize() -
ttl
-
ttlAfterAccess
-
statsRecorded
public boolean statsRecorded() -
bounded
public boolean bounded()
-