High-performance cache policies and supporting data structures.
This store module is implemented in cachekit::store::weight and provides a weight-aware store that enforces both an entry-count limit and a total weight limit (typically “bytes”). For an overview of all store types, see docs/stores/README.md.
Arc<V> values in a HashMap<K, WeightEntry<V>>.total_weight to enforce a weight capacity.F: Fn(&V) -> usize.capacity()) and total weight (capacity_weight()).try_insert returns Err(StoreFull) when inserting a new key would exceed the entry limit, or when inserting/updating would exceed the weight limit.remove and then record_eviction to keep eviction metrics accurate).WeightStore<K, V, F>: single-threaded weight-aware store.ConcurrentWeightStore<K, V, F>: RwLock-protected store for multi-threaded use.try_insert: insert/update by key while enforcing entry and weight limits.get: fetch by key (updates hit/miss counters).remove: delete by key and adjust total_weight.total_weight, capacity_weight, clear.use std::sync::Arc;
use cachekit::store::traits::StoreMut;
use cachekit::store::weight::WeightStore;
let mut store = WeightStore::with_capacity(10, 64, |v: &String| v.len());
store.try_insert("k1", Arc::new("value".to_string())).unwrap();
assert!(store.total_weight() <= store.capacity_weight());
use std::sync::Arc;
use cachekit::store::traits::ConcurrentStore;
use cachekit::store::weight::ConcurrentWeightStore;
let store = ConcurrentWeightStore::with_capacity(10, 64, |v: &String| v.len());
store.try_insert("k1", Arc::new("value".to_string())).unwrap();
assert!(store.total_weight() <= store.capacity_weight());
K: Eq + Hash for key lookup.F: Fn(&V) -> usize to compute weight.WeightStore is single-threaded.ConcurrentWeightStore is Send + Sync via RwLock.total_weight (can fail with StoreFull).ConcurrentWeightStore, get takes a write lock because it updates metrics; this can increase contention in read-heavy workloads.ConcurrentWeightStore, the weight function must be Send + Sync (capture-only thread-safe state).