Available on crate feature
cache only.Expand description
In-memory cache with per-source TTL, metrics, and invalidation.
Wraps moka to provide a concurrent, async-friendly cache with
TinyLFU eviction. Matches hyperi-pylib’s cache module API:
per-source TTL configuration, get/set/invalidate_source.
§Config Cascade
cache:
max_capacity: 10000
default_ttl_secs: 3600
source_ttls:
http: 86400
db: 1800
search: 3600§Usage
use hyperi_rustlib::cache::{Cache, CacheConfig};
#[tokio::main]
async fn main() {
let cache = Cache::new(CacheConfig::default());
// Set with source-specific TTL
cache.set("http", "https://api.example.com", "response_data").await.expect("cache set");
// Get
if let Some(value) = cache.get::<String>("http", "https://api.example.com").await {
println!("cached: {value}");
}
// Invalidate all entries for a source
cache.invalidate_source("http").await;
}Re-exports§
pub use config::CacheConfig;
Modules§
- config
- Cache configuration with per-source TTL support.
Structs§
- Cache
- In-memory cache with per-source TTL and source-aware keys.