Skip to main content

CachePolicy

Trait CachePolicy 

Source
pub trait CachePolicy<K>: Send + Sync
where K: Eq + Hash + Clone + Send + Sync + 'static,
{ // 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§

Source

fn kind(&self) -> CachePolicyKind

Policy kind (for telemetry + configuration reflection).

Source

fn admit(&self, key: &K, weight_bytes: u64) -> CacheAdmission

Decide whether an entry should be admitted.

Source

fn record_hit(&self, key: &K) -> bool

Record a cache hit (returns whether the hit was served from the protected set).

Source

fn invalidate(&self, key: &K)

Remove policy metadata for a key (called when entries are explicitly cleared).

Source

fn drain_evictions(&self) -> Vec<CachePolicyEviction<K>>

Drain pending eviction events generated by the policy implementation.

Source

fn reset(&self)

Reset policy state (used when wiping the cache).

Source

fn stats(&self) -> CachePolicyMetrics

Snapshot policy metrics.

Implementors§