pub struct Builder { /* private fields */ }Expand description
A builder used to configure and construct a CuckooCache.
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn item_size(self, bytes: usize) -> Self
pub fn item_size(self, bytes: usize) -> Self
Set the fixed size in bytes for each item slot. Key, value, and per-item overhead must fit within this size.
use cuckoo_cache::CuckooCache;
let cache = CuckooCache::builder().item_size(128).build();Sourcepub fn nitem(self, nitem: usize) -> Self
pub fn nitem(self, nitem: usize) -> Self
Set the maximum number of items the cache can hold.
use cuckoo_cache::CuckooCache;
let cache = CuckooCache::builder().nitem(4096).build();Sourcepub fn max_displace(self, depth: usize) -> Self
pub fn max_displace(self, depth: usize) -> Self
Set the maximum displacement depth during insertion. Higher values reduce evictions at the cost of longer worst-case insertion times.
use cuckoo_cache::CuckooCache;
let cache = CuckooCache::builder().max_displace(4).build();Sourcepub fn policy(self, policy: Policy) -> Self
pub fn policy(self, policy: Policy) -> Self
Set the eviction policy.
use cuckoo_cache::{CuckooCache, Policy};
let cache = CuckooCache::builder().policy(Policy::Expire).build();Sourcepub fn max_ttl(self, seconds: u32) -> Self
pub fn max_ttl(self, seconds: u32) -> Self
Set the maximum TTL in seconds. Items with a TTL exceeding this value will have their TTL clamped.
use cuckoo_cache::CuckooCache;
let cache = CuckooCache::builder().max_ttl(86400).build();Sourcepub fn build(self) -> CuckooCache
pub fn build(self) -> CuckooCache
Consume the builder and allocate a CuckooCache.
use cuckoo_cache::{CuckooCache, Policy};
let cache = CuckooCache::builder()
.nitem(4096)
.item_size(64)
.policy(Policy::Random)
.build();Trait Implementations§
Auto Trait Implementations§
impl Freeze for Builder
impl RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnsafeUnpin for Builder
impl UnwindSafe for Builder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more