Expand description
Advanced query result cache with TTL and LRU eviction
This module provides a production-ready caching system for SPARQL query results with support for:
- Time-To-Live (TTL) expiration
- Least Recently Used (LRU) eviction
- Memory-aware cache management
- Concurrent access with minimal contention
- Cache statistics and monitoring
§Example
use oxirs_core::query::result_cache::{QueryResultCache, CacheConfig};
use std::time::Duration;
let config = CacheConfig {
max_entries: 1000,
max_memory_bytes: 100 * 1024 * 1024, // 100 MB
default_ttl: Duration::from_secs(300), // 5 minutes
enable_lru: true,
};
let cache = QueryResultCache::new(config);
// Cache a query result
let query = "SELECT * WHERE { ?s ?p ?o }".to_string();
let results = vec!["result1".to_string(), "result2".to_string()];
cache.put(query.clone(), results.clone());
// Retrieve from cache
if let Some(cached) = cache.get(&query) {
println!("Cache hit! Results: {:?}", cached);
}Structs§
- Cache
Config - Configuration for the query result cache
- Cache
Stats - Cache statistics for monitoring
- Query
Result Cache - Query result cache with TTL and LRU eviction