Skip to main content

Builder

Struct Builder 

Source
pub struct Builder { /* private fields */ }
Expand description

A builder used to configure and construct a CuckooCache.

Implementations§

Source§

impl Builder

Source

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

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

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

pub fn policy(self, policy: Policy) -> Self

Set the eviction policy.

use cuckoo_cache::{CuckooCache, Policy};

let cache = CuckooCache::builder().policy(Policy::Expire).build();
Source

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

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§

Source§

impl Default for Builder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.