1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Multi-layer cache system for Maproom.
//!
//! This module provides a unified cache system with multiple layers:
//! - **L1 Query Cache**: Caches search results (100 entries, 1 hour TTL)
//! - **L2 Embedding Cache**: Caches embedding vectors (1000 entries, 24 hour TTL)
//! - **L3 Context Cache**: Caches context bundles (500 entries, 30 min TTL)
//! - **Parse Tree Cache**: Caches parsed ASTs (memory-bounded)
//!
//! # Architecture
//!
//! The cache system uses LRU eviction and TTL-based expiration:
//! - Each cache layer is independently sized and configured
//! - Thread-safe access using Arc<RwLock<>>
//! - Atomic counters for statistics tracking
//! - Configurable TTL per cache layer
//!
//! # Performance Goals
//!
//! - Cache hit rate: >60% (target from PERF_OPT-4001)
//! - Memory usage: <500MB with all caches
//! - Thread-safe concurrent access
//! - Minimal contention with RwLock
//!
//! # Cache Management (PERF_OPT-4002)
//!
//! Cache management features include:
//! - **Eviction policies**: LRU, TTL, size-based, access-count
//! - **Warming strategies**: Startup, predictive, scheduled, manual
//! - **Invalidation logic**: File changes, re-indexing, pattern-based
//! - **Background maintenance**: Periodic cleanup, monitoring, alerts
//!
//! # Example
//!
//! ```no_run
//! use maproom::cache::{CacheSystem, CacheConfig};
//! use maproom::cache::maintenance::{CacheMaintenance, MaintenanceConfig};
//! use std::sync::Arc;
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//! let config = CacheConfig::default();
//! let cache_system = Arc::new(CacheSystem::new(config));
//!
//! // Use L1 query cache
//! let query_key = "search term".to_string();
//! if let Some(results) = cache_system.get_query(&query_key).await {
//! println!("Cache hit!");
//! }
//!
//! // Get overall cache statistics
//! let stats = cache_system.stats().await;
//! println!("Overall hit rate: {:.1}%", stats.overall_hit_rate() * 100.0);
//!
//! // Spawn background maintenance
//! let maintenance_config = MaintenanceConfig::default();
//! let maintenance = CacheMaintenance::new(Arc::clone(&cache_system), maintenance_config);
//! tokio::spawn(async move {
//! maintenance.run().await.ok();
//! });
//!
//! Ok(())
//! }
//! ```
pub use CacheEntry;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;