pub struct CacheConfig { /* private fields */ }Expand description
Tuning for a CachedIndex — the Tier-2 configured path.
Build one with CacheConfig::new and the chaining setters, then hand it to
CachedIndex::with_config. Every setting
has a sensible default, so CacheConfig::new() alone is a valid config.
| Setting | Default | Meaning |
|---|---|---|
capacity | 1024 | Max distinct searches cached; 0 disables caching. |
ttl | none | Optional per-entry time-to-live; expired results are recomputed. |
policy | Lru | Which entry to evict when full. |
§Examples
use std::time::Duration;
use iqdb_cache::{CacheConfig, CachedIndex, EvictionPolicy};
let config = CacheConfig::new()
.capacity(4096)
.ttl(Duration::from_secs(30))
.policy(EvictionPolicy::Lfu);
let cached = CachedIndex::with_config(iqdb_cache::doc_stub::stub_index(), config);
assert_eq!(cached.capacity(), 4096);
assert_eq!(cached.ttl(), Some(Duration::from_secs(30)));
assert_eq!(cached.policy(), EvictionPolicy::Lfu);Implementations§
Source§impl CacheConfig
impl CacheConfig
Sourcepub fn new() -> Self
pub fn new() -> Self
A configuration with the default capacity (1024), no TTL, and the LRU policy.
§Examples
use iqdb_cache::CacheConfig;
let config = CacheConfig::new();
// Equivalent to `CachedIndex::new(..)`'s defaults.Sourcepub fn policy(self, policy: EvictionPolicy) -> Self
pub fn policy(self, policy: EvictionPolicy) -> Self
Sets the eviction policy applied when the cache is full.
§Examples
use iqdb_cache::{CacheConfig, EvictionPolicy};
let config = CacheConfig::new().policy(EvictionPolicy::Arc);Sourcepub fn capacity(self, capacity: usize) -> Self
pub fn capacity(self, capacity: usize) -> Self
Sets the maximum number of distinct cached searches.
A capacity of 0 disables caching: searches pass straight through.
§Examples
use iqdb_cache::CacheConfig;
let config = CacheConfig::new().capacity(256);Sourcepub fn ttl(self, ttl: Duration) -> Self
pub fn ttl(self, ttl: Duration) -> Self
Sets a per-entry time-to-live: a cached result older than ttl is
treated as a miss and recomputed.
TTL bounds staleness from changes the wrapper cannot observe (for example, the wrapped index mutated through another handle). Mutations through the wrapper already invalidate exactly, independent of TTL.
§Examples
use std::time::Duration;
use iqdb_cache::CacheConfig;
let config = CacheConfig::new().ttl(Duration::from_secs(60));Trait Implementations§
Source§impl Clone for CacheConfig
impl Clone for CacheConfig
Source§fn clone(&self) -> CacheConfig
fn clone(&self) -> CacheConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CacheConfig
impl Debug for CacheConfig
Source§impl Default for CacheConfig
impl Default for CacheConfig
impl Eq for CacheConfig
Source§impl PartialEq for CacheConfig
impl PartialEq for CacheConfig
Source§fn eq(&self, other: &CacheConfig) -> bool
fn eq(&self, other: &CacheConfig) -> bool
self and other values to be equal, and is used by ==.