pub trait CachePolicy<K>: Send + Sync{
// Required methods
fn kind(&self) -> CachePolicyKind;
fn admit(&self, key: &K, weight_bytes: u64) -> CacheAdmission;
fn record_hit(&self, key: &K) -> bool;
fn invalidate(&self, key: &K);
fn drain_evictions(&self) -> Vec<CachePolicyEviction<K>>;
fn reset(&self);
fn stats(&self) -> CachePolicyMetrics;
}Expand description
Policy abstraction consumed by caches.
Required Methods§
Sourcefn kind(&self) -> CachePolicyKind
fn kind(&self) -> CachePolicyKind
Policy kind (for telemetry + configuration reflection).
Sourcefn admit(&self, key: &K, weight_bytes: u64) -> CacheAdmission
fn admit(&self, key: &K, weight_bytes: u64) -> CacheAdmission
Decide whether an entry should be admitted.
Sourcefn record_hit(&self, key: &K) -> bool
fn record_hit(&self, key: &K) -> bool
Record a cache hit (returns whether the hit was served from the protected set).
Sourcefn invalidate(&self, key: &K)
fn invalidate(&self, key: &K)
Remove policy metadata for a key (called when entries are explicitly cleared).
Sourcefn drain_evictions(&self) -> Vec<CachePolicyEviction<K>>
fn drain_evictions(&self) -> Vec<CachePolicyEviction<K>>
Drain pending eviction events generated by the policy implementation.
Sourcefn stats(&self) -> CachePolicyMetrics
fn stats(&self) -> CachePolicyMetrics
Snapshot policy metrics.