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. |
§Examples
use std::time::Duration;
use iqdb_cache::{CacheConfig, CachedIndex};
let config = CacheConfig::new()
.capacity(4096)
.ttl(Duration::from_secs(30));
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)));Implementations§
Source§impl CacheConfig
impl CacheConfig
Sourcepub fn new() -> Self
pub fn new() -> Self
A configuration with the default capacity (1024) and no TTL.
§Examples
use iqdb_cache::CacheConfig;
let config = CacheConfig::new();
// Equivalent to `CachedIndex::new(..)`'s defaults.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
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
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
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for CacheConfig
Auto Trait Implementations§
impl Freeze for CacheConfig
impl RefUnwindSafe for CacheConfig
impl Send for CacheConfig
impl Sync for CacheConfig
impl Unpin for CacheConfig
impl UnsafeUnpin for CacheConfig
impl UnwindSafe for CacheConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more