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
impl OptionsBuilder
pub fn new() -> Self
Sourcepub fn shards(&mut self, shards: usize) -> &mut Self
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.
Sourcepub fn estimated_items_capacity(
&mut self,
estimated_items_capacity: usize,
) -> &mut Self
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.
Sourcepub fn weight_capacity(&mut self, weight_capacity: u64) -> &mut Self
pub fn weight_capacity(&mut self, weight_capacity: u64) -> &mut Self
The max weight that the cache can hold.
Sourcepub fn hot_allocation(&mut self, hot_allocation: f64) -> &mut Self
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%).
Sourcepub fn ghost_allocation(&mut self, ghost_allocation: f64) -> &mut Self
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%).
Trait Implementations§
Source§impl Clone for OptionsBuilder
impl Clone for OptionsBuilder
Source§fn clone(&self) -> OptionsBuilder
fn clone(&self) -> OptionsBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more