CacheKit Docs

High-performance cache policies and supporting data structures.

View the Project on GitHub OxidizeLabs/cachekit

Weight store

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.

Architecture

Capacity Semantics

Key Components

Core Operations

Performance Trade-offs

When to Use

Example Usage

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());

Example: Concurrent usage

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());

Type Constraints

Thread Safety

Implementation Notes

Weight Function Guidelines