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,
impl<Key, Value> ConfigBuilder<Key, Value>where
Key: Hash + 'static,
Value: 'static,
Sourcepub fn new(
counters: TotalCounters,
capacity: TotalCapacity,
cache_weight: Weight,
) -> Self
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
Sourcepub fn key_hash_fn(
self,
key_hash: Box<HashFn<Key>>,
) -> ConfigBuilder<Key, Value>
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.
Sourcepub fn weight_calculation_fn(
self,
weight_calculation: Box<WeightCalculationFn<Key, Value>>,
) -> ConfigBuilder<Key, Value>
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.
Sourcepub fn clock(self, clock: ClockType) -> ConfigBuilder<Key, Value>
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.
Sourcepub fn access_pool_size(self, pool_size: usize) -> ConfigBuilder<Key, Value>
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.
Sourcepub fn access_buffer_size(self, buffer_size: usize) -> ConfigBuilder<Key, Value>
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.
Sourcepub fn command_buffer_size(
self,
command_buffer_size: usize,
) -> ConfigBuilder<Key, Value>
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.
Sourcepub fn shards(self, shards: TotalShards) -> ConfigBuilder<Key, Value>
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.
Sourcepub fn ttl_tick_duration(self, duration: Duration) -> ConfigBuilder<Key, Value>
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.