OptionsBuilder

Struct OptionsBuilder 

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

Builder for Options.

§Example

use quick_cache::{sync::{Cache, DefaultLifecycle}, OptionsBuilder, UnitWeighter, DefaultHashBuilder};

Cache::<String, String>::with_options(
  OptionsBuilder::new()
    .estimated_items_capacity(10000)
    .weight_capacity(10000)
    .build()
    .unwrap(),
    UnitWeighter,
    DefaultHashBuilder::default(),
    DefaultLifecycle::default(),
);

Implementations§

Source§

impl OptionsBuilder

Source

pub fn new() -> Self

Source

pub fn shards(&mut self, shards: usize) -> &mut Self

Set the number of internal shards for the sync cache. Each shard has independent synchronization and capacity. This means that the Cache can be used from multiple threads with little contention but the capacity of each shard is a portion of the total.

Defaults to: number of detected cores * 4

Note that this number isn’t enforced and will be adjusted internally to the next power of two. Too small shards (depending on estimated capacity) may also cause the actual shard count to decrease.

Source

pub fn estimated_items_capacity( &mut self, estimated_items_capacity: usize, ) -> &mut Self

The estimated number of items the cache is expected to hold, roughly equivalent to weight_capacity / average item weight. An estimation within one or even two orders of magnitude of the real value is often good enough.

This is used to estimate the maximum number of shards (to avoid shards that are too small) and to estimate space required to track items recently evicted from the cache.

Source

pub fn weight_capacity(&mut self, weight_capacity: u64) -> &mut Self

The max weight that the cache can hold.

Source

pub fn hot_allocation(&mut self, hot_allocation: f64) -> &mut Self

What percentage [0..=1.0] of the cache space to reserve for “hot” items. If your workload exhibit heavy bias towards recency instead of frequency try lowering this setting. In practice the useful ranges are between 50% to 99% (usually on the higher side).

Defaults to: 0.97 (97%).

Source

pub fn ghost_allocation(&mut self, ghost_allocation: f64) -> &mut Self

The cache optimistically tracks recently seen keys that are not resident in the cache. These keys are called ghost keys. If a ghost key is seen again items it will be admitted as “hot”. The ghost allocation percentage defines how much space to allocate for the ghost keys considering the estimated_items_capacity.

Defaults to: 0.5 (50%).

Source

pub fn build(&self) -> Result<Options, Error>

Builds an Option struct which can be used in the Cache::with_options constructor.

Trait Implementations§

Source§

impl Clone for OptionsBuilder

Source§

fn clone(&self) -> OptionsBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OptionsBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for OptionsBuilder

Source§

fn default() -> OptionsBuilder

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.