pub struct TTLConfig {
pub default_ttl: Option<Duration>,
pub refresh_on_read: bool,
pub sweep_interval: Duration,
pub sweep_max_items: usize,
}Expand description
Configuration for time-to-live (TTL) behavior on MemoryStore.
Controls automatic expiration of items using both lazy evaluation on read
and periodic background sweep tasks. Expired items are detected and removed
during get() and search() operations, and can be cleaned up in bulk
via the background sweep mechanism.
§Examples
use juncture_core::store::{MemoryStore, TTLConfig};
use std::time::Duration;
let store = MemoryStore::new().with_ttl_config(TTLConfig {
default_ttl: Some(Duration::from_secs(300)),
refresh_on_read: true,
..Default::default()
});Fields§
§default_ttl: Option<Duration>Default TTL duration applied to items inserted via put().
When None, items never expire (the default).
When Some(duration), each put() sets expires_at = now + duration.
refresh_on_read: boolWhether to extend an item’s expiration time when it is read via get().
When true and default_ttl is set, a successful get() will update
the item’s expires_at to now + default_ttl, effectively resetting
its TTL timer.
sweep_interval: DurationInterval between background sweep cleanup cycles.
The background sweep task runs periodically to remove expired items
in bulk, preventing unbounded growth of the store. Each sweep pass
processes at most sweep_max_items expired items to avoid blocking
other operations for extended periods.
sweep_max_items: usizeMaximum number of items to sweep per background cleanup cycle.
Limits the work done by a single sweep pass. Each sweep cycle will remove at most this many expired items, ensuring predictable cleanup times even with large numbers of expired entries.