Represents a cache eviction strategy for determining which cache entry should be removed when the cache reaches capacity or when specific conditions are met.
In caching systems, it's important to manage limited memory or storage efficiently. Eviction policies encapsulate the logic used to select entries to remove in order to make space for new data. By abstracting this logic, caches can be flexible and support multiple eviction strategies without changing the core caching implementation.
Implementations of this interface may interface decisions on various factors:
- Access patterns (e.g., Least Recently Used, Most Recently Used)
LRU - Frequency of access (e.g., Least Frequently Used)
LFU - Time-based expiration (e.g., TTL - Time To Live)
- FIFO (First In First Out): Evict the oldest entry
- Custom business rules (e.g., priority-based eviction)
Example usage:
final policy = LruEvictionPolicy();
final keyToEvict = policy.determineEvictionCandidate(cache.entries);
if (keyToEvict != null) {
cache.evict(keyToEvict);
}
By providing the getName() method, different policies can also be
identified for logging, metrics, or debugging purposes.
- Implementers
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
determineEvictionCandidate(
Map< Object, Cache> entries) → FutureOr<Object?> - Determines which entry in the cache should be evicted.
-
getName(
) → String - Returns a descriptive name for this eviction policy.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited