pub struct CacheBuilder { /* private fields */ }Expand description
Builder for cache instances.
§Examples
use oxistore_cache::builder::{CacheBuilder, CachePolicy};
let lru = CacheBuilder::new(128)
.policy(CachePolicy::Lru)
.build_lru();
let arc = CacheBuilder::new(256)
.policy(CachePolicy::Arc)
.build_arc();Implementations§
Source§impl CacheBuilder
impl CacheBuilder
Sourcepub fn policy(self, p: CachePolicy) -> Self
pub fn policy(self, p: CachePolicy) -> Self
Set the eviction policy.
Sourcepub fn max_bytes(self, b: usize) -> Self
pub fn max_bytes(self, b: usize) -> Self
Set a byte-budget limit (used by CacheBuilder::build_bounded_lru).
Sourcepub fn n_shards(self, n: usize) -> Self
pub fn n_shards(self, n: usize) -> Self
Set the number of shards (used by CacheBuilder::build_sharded).
Must be a power of two.
Sourcepub fn build_lru(self) -> LruCache<Vec<u8>, Vec<u8>>
pub fn build_lru(self) -> LruCache<Vec<u8>, Vec<u8>>
Build a LruCache with the configured capacity.
Sourcepub fn build_arc(self) -> ArcCache<Vec<u8>, Vec<u8>>
pub fn build_arc(self) -> ArcCache<Vec<u8>, Vec<u8>>
Build an ArcCache with the configured capacity.
Sourcepub fn build_lfu(self) -> LfuCache<Vec<u8>, Vec<u8>>
pub fn build_lfu(self) -> LfuCache<Vec<u8>, Vec<u8>>
Build an LfuCache with the configured capacity.
Sourcepub fn build_wtinylfu(self) -> WTinyLfuCache<Vec<u8>, Vec<u8>>
pub fn build_wtinylfu(self) -> WTinyLfuCache<Vec<u8>, Vec<u8>>
Build a WTinyLfuCache with the configured capacity.
Sourcepub fn build_bounded_lru(self) -> BoundedCache<LruCache<Vec<u8>, Vec<u8>>>
pub fn build_bounded_lru(self) -> BoundedCache<LruCache<Vec<u8>, Vec<u8>>>
Build a BoundedCache wrapping an LRU inner cache.
Uses max_bytes if set; otherwise defaults to capacity * 64 (a rough
64-byte average per entry).
Sourcepub fn build_sharded(self) -> ShardedCache
pub fn build_sharded(self) -> ShardedCache
Build a ShardedCache with LRU shards.
Uses n_shards if set; otherwise defaults to 8.
The capacity is split evenly across shards (capacity / n_shards).
§Panics
Panics if the resolved n_shards is not a power of two or is zero.
Trait Implementations§
Source§impl Clone for CacheBuilder
impl Clone for CacheBuilder
Source§fn clone(&self) -> CacheBuilder
fn clone(&self) -> CacheBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more