ConfigBuilder

Struct ConfigBuilder 

Source
pub struct ConfigBuilder<Key, Value>
where Key: Hash + 'static, Value: 'static,
{ /* private fields */ }
Expand description

Convenient builder that allows creating an instance of Config.

Implementations§

Source§

impl<Key, Value> ConfigBuilder<Key, Value>
where Key: Hash + 'static, Value: 'static,

Source

pub fn new( counters: TotalCounters, capacity: TotalCapacity, cache_weight: Weight, ) -> Self

Create a new instance of ConfigBuilder with counters, capacity and cache_weight.

counters are used to determine the number of counters to keep that hold the access frequency of each key.

If you expect your cache to hold 10_000 elements, then counters should be 10 times (100_000) to get a close estimate of the access frequency.

capacity is used as a parameter for dashmap::DashMap inside crate::cache::store::Store. It defines the number of items that the cache may store.

cache_weight defines the total cache size. cache_weight is treated as the cache size in bytes. If cache_weight is set to 1024, that means the cache should take only 1024 bytes of memory. After the cache size is full, any further put operation will result in either of the following:

  • rejection of the incoming key

  • admission of the incoming key by causing eviction of some existing keys

Source

pub fn key_hash_fn( self, key_hash: Box<HashFn<Key>>, ) -> ConfigBuilder<Key, Value>

Sets the key hash function.

By default, DefaultHasher is used that uses SipHasher13 as the hash function.

Source

pub fn weight_calculation_fn( self, weight_calculation: Box<WeightCalculationFn<Key, Value>>, ) -> ConfigBuilder<Key, Value>

Sets the weight calculation function.

Weight calculation function calculates the weight of the incoming key/value pair.

Default is the perform function defined in crate::cache::config::weight_calculation::Calculation.

Source

pub fn clock(self, clock: ClockType) -> ConfigBuilder<Key, Value>

Sets the clock to be used to get the current time. By default crate::cache::clock::SystemClock is used.

Source

pub fn access_pool_size(self, pool_size: usize) -> ConfigBuilder<Key, Value>

Sets the pool size.

Pool represents a ring-buffer that is used to buffer the gets for various keys.

Default pool size is 32.

Source

pub fn access_buffer_size(self, buffer_size: usize) -> ConfigBuilder<Key, Value>

Sets the size of each buffer inside Pool.

Default capacity of the buffer is 64.

Source

pub fn command_buffer_size( self, command_buffer_size: usize, ) -> ConfigBuilder<Key, Value>

Each put, put_or_update, delete results in a command to crate::cache::command::command_executor::CommandExecutor.

CommandExecutor reads from a channel and the default channel size is 32 * 1024.

Source

pub fn shards(self, shards: TotalShards) -> ConfigBuilder<Key, Value>

Sets the number of shards to use in the DashMap inside crate::cache::store::Store.

shards must be a power of 2 and greater than 1.

Source

pub fn ttl_tick_duration(self, duration: Duration) -> ConfigBuilder<Key, Value>

Sets the duration of the crate::cache::expiration::TTLTicker.

Default is every 5 seconds.

Source

pub fn build(self) -> Config<Key, Value>

Auto Trait Implementations§

§

impl<Key, Value> Freeze for ConfigBuilder<Key, Value>

§

impl<Key, Value> !RefUnwindSafe for ConfigBuilder<Key, Value>

§

impl<Key, Value> Send for ConfigBuilder<Key, Value>

§

impl<Key, Value> Sync for ConfigBuilder<Key, Value>

§

impl<Key, Value> Unpin for ConfigBuilder<Key, Value>

§

impl<Key, Value> !UnwindSafe for ConfigBuilder<Key, Value>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V