ReadCache<K, V> class

Read cache with LRU and LFU eviction strategies and optional TTL.

Constructors

ReadCache({required int maxSize, CacheStrategy strategy = CacheStrategy.lru, Duration? defaultTTL})
Create a ReadCache with the given maxSize and strategy.

Properties

defaultTTL Duration?
Get the current default TTL.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
hitRate double
The cache hit rate as a value between 0.0 and 1.0.
no setter
keys List<K>
Get all keys currently in the cache (non-expired).
no setter
maxSize int
Maximum number of entries the cache can hold.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
size int
The current number of entries in the cache.
no setter
stats CacheStats
Get the current cache statistics.
no setter
strategy CacheStrategy
The eviction strategy to use when the cache is full.
final
values List<V>
Get all values currently in the cache (non-expired).
no setter

Methods

clear() → void
Clear all entries from the cache.
containsKey(K key) bool
Check if the cache contains an entry for key.
get(K key) → V?
Get the value associated with key, or null if not found or expired.
getRemainingTTL(K key) Duration?
Get the remaining TTL for a key, or null if no TTL or doesn't exist.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
put(K key, V value, {Duration? ttl}) → void
Put a value in the cache at key.
remove(K key) → void
Remove the entry associated with key.
resetStats() → void
Reset hit/miss counters while preserving cached entries.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited