maproom 0.1.0

Semantic code search powered by embeddings and SQLite
Documentation
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
//! Multi-layer cache system implementation.
//!
//! Provides unified cache management with L1/L2/L3 caches and parse tree cache.

use super::entry::CacheEntry;
use super::stats::{CacheStats, MultiLayerStats};
use crate::context::types::ContextBundle;
use crate::search::results::FinalSearchResults;
use lru::LruCache;
use serde::{Deserialize, Serialize};
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::num::NonZeroUsize;
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::RwLock;
use tracing::{debug, info};

/// Type alias for embedding vectors.
pub type Vector = Vec<f32>;

/// Cache configuration for the multi-layer cache system.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CacheConfig {
    /// L1 query cache configuration
    pub l1_query: LayerConfig,
    /// L2 embedding cache configuration
    pub l2_embedding: LayerConfig,
    /// L3 context cache configuration
    pub l3_context: LayerConfig,
    /// Parse tree cache configuration
    pub parse_tree: LayerConfig,
}

impl Default for CacheConfig {
    fn default() -> Self {
        Self {
            l1_query: LayerConfig {
                max_entries: 100,
                ttl_seconds: 3600, // 1 hour
                enabled: true,
            },
            l2_embedding: LayerConfig {
                max_entries: 1000,
                ttl_seconds: 86400, // 24 hours
                enabled: true,
            },
            l3_context: LayerConfig {
                max_entries: 500,
                ttl_seconds: 1800, // 30 minutes
                enabled: true,
            },
            parse_tree: LayerConfig {
                max_entries: 200,
                ttl_seconds: 0, // Never expire (until file changes)
                enabled: true,
            },
        }
    }
}

/// Configuration for a single cache layer.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LayerConfig {
    /// Maximum number of entries
    pub max_entries: usize,
    /// Time-to-live in seconds (0 = never expire)
    pub ttl_seconds: u64,
    /// Whether this layer is enabled
    pub enabled: bool,
}

/// Multi-layer cache system.
///
/// Provides unified cache management with:
/// - L1: Query result cache (100 entries, 1 hour TTL)
/// - L2: Embedding cache (1000 entries, 24 hour TTL)
/// - L3: Context bundle cache (500 entries, 30 min TTL)
/// - Parse tree cache (200 entries, never expire until file changes)
pub struct CacheSystem {
    /// L1: Query result cache
    l1_query: Arc<RwLock<LruCache<String, CacheEntry<FinalSearchResults>>>>,
    l1_stats: Arc<CacheStats>,
    l1_ttl: Duration,
    l1_enabled: bool,

    /// L2: Embedding cache
    l2_embedding: Arc<RwLock<LruCache<String, CacheEntry<Vector>>>>,
    l2_stats: Arc<CacheStats>,
    l2_ttl: Duration,
    l2_enabled: bool,

    /// L3: Context bundle cache
    l3_context: Arc<RwLock<LruCache<u64, CacheEntry<ContextBundle>>>>,
    l3_stats: Arc<CacheStats>,
    l3_ttl: Duration,
    l3_enabled: bool,

    /// Parse tree cache (stores serialized tree-sitter trees)
    parse_tree: Arc<RwLock<LruCache<String, CacheEntry<Vec<u8>>>>>,
    parse_tree_stats: Arc<CacheStats>,
    parse_tree_ttl: Duration,
    parse_tree_enabled: bool,
}

impl CacheSystem {
    /// Create a new multi-layer cache system with the given configuration.
    pub fn new(config: CacheConfig) -> Self {
        info!(
            "Initializing multi-layer cache system (L1: {}, L2: {}, L3: {}, ParseTree: {})",
            config.l1_query.max_entries,
            config.l2_embedding.max_entries,
            config.l3_context.max_entries,
            config.parse_tree.max_entries
        );

        Self {
            // L1: Query cache
            l1_query: Arc::new(RwLock::new(LruCache::new(
                NonZeroUsize::new(config.l1_query.max_entries).unwrap(),
            ))),
            l1_stats: Arc::new(CacheStats::new()),
            l1_ttl: Duration::from_secs(config.l1_query.ttl_seconds),
            l1_enabled: config.l1_query.enabled,

            // L2: Embedding cache
            l2_embedding: Arc::new(RwLock::new(LruCache::new(
                NonZeroUsize::new(config.l2_embedding.max_entries).unwrap(),
            ))),
            l2_stats: Arc::new(CacheStats::new()),
            l2_ttl: Duration::from_secs(config.l2_embedding.ttl_seconds),
            l2_enabled: config.l2_embedding.enabled,

            // L3: Context cache
            l3_context: Arc::new(RwLock::new(LruCache::new(
                NonZeroUsize::new(config.l3_context.max_entries).unwrap(),
            ))),
            l3_stats: Arc::new(CacheStats::new()),
            l3_ttl: Duration::from_secs(config.l3_context.ttl_seconds),
            l3_enabled: config.l3_context.enabled,

            // Parse tree cache
            parse_tree: Arc::new(RwLock::new(LruCache::new(
                NonZeroUsize::new(config.parse_tree.max_entries).unwrap(),
            ))),
            parse_tree_stats: Arc::new(CacheStats::new()),
            parse_tree_ttl: Duration::from_secs(config.parse_tree.ttl_seconds),
            parse_tree_enabled: config.parse_tree.enabled,
        }
    }

    // === L1: Query Cache ===

    /// Get a cached query result.
    pub async fn get_query(&self, query: &str) -> Option<FinalSearchResults> {
        if !self.l1_enabled {
            return None;
        }

        let key = Self::hash_key(query);
        let mut cache = self.l1_query.write().await;

        if let Some(entry) = cache.get(&key) {
            if entry.is_expired(self.l1_ttl) {
                cache.pop(&key);
                self.l1_stats.record_expiration();
                self.l1_stats.record_miss();
                debug!("L1 cache EXPIRED: {}", query);
                None
            } else {
                self.l1_stats.record_hit();
                debug!("L1 cache HIT: {}", query);
                Some(entry.value.clone())
            }
        } else {
            self.l1_stats.record_miss();
            debug!("L1 cache MISS: {}", query);
            None
        }
    }

    /// Put a query result into the cache.
    pub async fn put_query(&self, query: &str, results: FinalSearchResults) {
        if !self.l1_enabled {
            return;
        }

        let key = Self::hash_key(query);
        let entry = CacheEntry::new(results);

        let mut cache = self.l1_query.write().await;
        if cache.len() >= cache.cap().get() && !cache.contains(&key) {
            self.l1_stats.record_eviction();
        }

        cache.put(key, entry);
        self.l1_stats.record_insertion();
        debug!("L1 cache PUT: {}", query);
    }

    /// Clear the L1 query cache.
    pub async fn clear_l1(&self) {
        let mut cache = self.l1_query.write().await;
        cache.clear();
        info!("L1 query cache cleared");
    }

    // === L2: Embedding Cache ===

    /// Get a cached embedding.
    pub async fn get_embedding(&self, text: &str) -> Option<Vector> {
        if !self.l2_enabled {
            return None;
        }

        let key = Self::hash_key(text);
        let mut cache = self.l2_embedding.write().await;

        if let Some(entry) = cache.get(&key) {
            if entry.is_expired(self.l2_ttl) {
                cache.pop(&key);
                self.l2_stats.record_expiration();
                self.l2_stats.record_miss();
                debug!("L2 cache EXPIRED: text hash {}", &key[..8]);
                None
            } else {
                self.l2_stats.record_hit();
                debug!("L2 cache HIT: text hash {}", &key[..8]);
                Some(entry.value.clone())
            }
        } else {
            self.l2_stats.record_miss();
            debug!("L2 cache MISS: text hash {}", &key[..8]);
            None
        }
    }

    /// Put an embedding into the cache.
    pub async fn put_embedding(&self, text: &str, vector: Vector) {
        if !self.l2_enabled {
            return;
        }

        let key = Self::hash_key(text);
        let entry = CacheEntry::new(vector);

        let mut cache = self.l2_embedding.write().await;
        if cache.len() >= cache.cap().get() && !cache.contains(&key) {
            self.l2_stats.record_eviction();
        }

        cache.put(key, entry);
        self.l2_stats.record_insertion();
        debug!("L2 cache PUT: text hash {}", &Self::hash_key(text)[..8]);
    }

    /// Clear the L2 embedding cache.
    pub async fn clear_l2(&self) {
        let mut cache = self.l2_embedding.write().await;
        cache.clear();
        info!("L2 embedding cache cleared");
    }

    // === L3: Context Cache ===

    /// Get a cached context bundle.
    pub async fn get_context(&self, chunk_ids: &[i64]) -> Option<ContextBundle> {
        if !self.l3_enabled {
            return None;
        }

        let key = Self::hash_chunk_ids(chunk_ids);
        let mut cache = self.l3_context.write().await;

        if let Some(entry) = cache.get(&key) {
            if entry.is_expired(self.l3_ttl) {
                cache.pop(&key);
                self.l3_stats.record_expiration();
                self.l3_stats.record_miss();
                debug!("L3 cache EXPIRED: key {}", key);
                None
            } else {
                self.l3_stats.record_hit();
                debug!("L3 cache HIT: key {}", key);
                Some(entry.value.clone())
            }
        } else {
            self.l3_stats.record_miss();
            debug!("L3 cache MISS: key {}", key);
            None
        }
    }

    /// Put a context bundle into the cache.
    pub async fn put_context(&self, chunk_ids: &[i64], bundle: ContextBundle) {
        if !self.l3_enabled {
            return;
        }

        let key = Self::hash_chunk_ids(chunk_ids);
        let entry = CacheEntry::new(bundle);

        let mut cache = self.l3_context.write().await;
        if cache.len() >= cache.cap().get() && !cache.contains(&key) {
            self.l3_stats.record_eviction();
        }

        cache.put(key, entry);
        self.l3_stats.record_insertion();
        debug!("L3 cache PUT: key {}", key);
    }

    /// Invalidate a context cache entry by chunk IDs.
    pub async fn invalidate_context(&self, chunk_ids: &[i64]) {
        let key = Self::hash_chunk_ids(chunk_ids);
        let mut cache = self.l3_context.write().await;
        cache.pop(&key);
        debug!("L3 cache INVALIDATE: key {}", key);
    }

    /// Clear the L3 context cache.
    pub async fn clear_l3(&self) {
        let mut cache = self.l3_context.write().await;
        cache.clear();
        info!("L3 context cache cleared");
    }

    // === Parse Tree Cache ===

    /// Get a cached parse tree.
    ///
    /// The key should be: `<file_path>:<content_hash>`
    pub async fn get_parse_tree(&self, file_path: &str, content_hash: &str) -> Option<Vec<u8>> {
        if !self.parse_tree_enabled {
            return None;
        }

        let key = format!("{}:{}", file_path, content_hash);
        let mut cache = self.parse_tree.write().await;

        if let Some(entry) = cache.get(&key) {
            if self.parse_tree_ttl.as_secs() > 0 && entry.is_expired(self.parse_tree_ttl) {
                cache.pop(&key);
                self.parse_tree_stats.record_expiration();
                self.parse_tree_stats.record_miss();
                debug!("ParseTree cache EXPIRED: {}", file_path);
                None
            } else {
                self.parse_tree_stats.record_hit();
                debug!("ParseTree cache HIT: {}", file_path);
                Some(entry.value.clone())
            }
        } else {
            self.parse_tree_stats.record_miss();
            debug!("ParseTree cache MISS: {}", file_path);
            None
        }
    }

    /// Put a parse tree into the cache.
    pub async fn put_parse_tree(&self, file_path: &str, content_hash: &str, tree_data: Vec<u8>) {
        if !self.parse_tree_enabled {
            return;
        }

        let key = format!("{}:{}", file_path, content_hash);
        let entry = CacheEntry::new(tree_data);

        let mut cache = self.parse_tree.write().await;
        if cache.len() >= cache.cap().get() && !cache.contains(&key) {
            self.parse_tree_stats.record_eviction();
        }

        cache.put(key, entry);
        self.parse_tree_stats.record_insertion();
        debug!("ParseTree cache PUT: {}", file_path);
    }

    /// Invalidate all parse tree entries for a given file path.
    pub async fn invalidate_parse_tree(&self, file_path: &str) {
        let mut cache = self.parse_tree.write().await;
        let prefix = format!("{}:", file_path);

        // Collect keys to remove
        let keys_to_remove: Vec<String> = cache
            .iter()
            .filter(|(key, _)| key.starts_with(&prefix))
            .map(|(key, _)| key.clone())
            .collect();

        // Remove entries
        for key in keys_to_remove {
            cache.pop(&key);
        }

        debug!("ParseTree cache INVALIDATE: {}", file_path);
    }

    /// Clear the parse tree cache.
    pub async fn clear_parse_tree(&self) {
        let mut cache = self.parse_tree.write().await;
        cache.clear();
        info!("Parse tree cache cleared");
    }

    // === Statistics ===

    /// Get statistics for all cache layers.
    pub async fn stats(&self) -> MultiLayerStats {
        MultiLayerStats {
            l1_query: self.l1_stats.snapshot(),
            l2_embedding: self.l2_stats.snapshot(),
            l3_context: self.l3_stats.snapshot(),
            parse_tree: self.parse_tree_stats.snapshot(),
        }
    }

    /// Get L1 statistics.
    pub fn l1_stats(&self) -> Arc<CacheStats> {
        Arc::clone(&self.l1_stats)
    }

    /// Get L2 statistics.
    pub fn l2_stats(&self) -> Arc<CacheStats> {
        Arc::clone(&self.l2_stats)
    }

    /// Get L3 statistics.
    pub fn l3_stats(&self) -> Arc<CacheStats> {
        Arc::clone(&self.l3_stats)
    }

    /// Get parse tree cache statistics.
    pub fn parse_tree_stats(&self) -> Arc<CacheStats> {
        Arc::clone(&self.parse_tree_stats)
    }

    /// Reset all statistics.
    pub fn reset_stats(&self) {
        self.l1_stats.reset();
        self.l2_stats.reset();
        self.l3_stats.reset();
        self.parse_tree_stats.reset();
        info!("All cache statistics reset");
    }

    /// Clear all caches.
    pub async fn clear_all(&self) {
        self.clear_l1().await;
        self.clear_l2().await;
        self.clear_l3().await;
        self.clear_parse_tree().await;
        info!("All caches cleared");
    }

    // === Helper Methods ===

    /// Generate a hash key from a string.
    fn hash_key<T: Hash + ?Sized>(value: &T) -> String {
        let mut hasher = DefaultHasher::new();
        value.hash(&mut hasher);
        format!("{:x}", hasher.finish())
    }

    /// Generate a hash key from chunk IDs.
    fn hash_chunk_ids(chunk_ids: &[i64]) -> u64 {
        let mut hasher = DefaultHasher::new();
        chunk_ids.hash(&mut hasher);
        hasher.finish()
    }
}

impl Clone for CacheSystem {
    fn clone(&self) -> Self {
        Self {
            l1_query: Arc::clone(&self.l1_query),
            l1_stats: Arc::clone(&self.l1_stats),
            l1_ttl: self.l1_ttl,
            l1_enabled: self.l1_enabled,

            l2_embedding: Arc::clone(&self.l2_embedding),
            l2_stats: Arc::clone(&self.l2_stats),
            l2_ttl: self.l2_ttl,
            l2_enabled: self.l2_enabled,

            l3_context: Arc::clone(&self.l3_context),
            l3_stats: Arc::clone(&self.l3_stats),
            l3_ttl: self.l3_ttl,
            l3_enabled: self.l3_enabled,

            parse_tree: Arc::clone(&self.parse_tree),
            parse_tree_stats: Arc::clone(&self.parse_tree_stats),
            parse_tree_ttl: self.parse_tree_ttl,
            parse_tree_enabled: self.parse_tree_enabled,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::search::results::{QueryProcessingDetails, SearchMetadata, SearchTiming};
    use crate::search::types::SearchMode;
    use std::collections::HashMap;

    fn create_test_results() -> FinalSearchResults {
        let query_processing = QueryProcessingDetails::new(
            "test".to_string(),
            SearchMode::Auto,
            1,
            0,
            "test".to_string(),
            false,
        );
        let result_counts = HashMap::new();
        let timing = SearchTiming::new(1.0, 1.0, 1.0, 1.0);
        let metadata = SearchMetadata::new(query_processing, result_counts, timing, 0, 0);
        FinalSearchResults::new("test".to_string(), vec![], metadata)
    }

    #[tokio::test]
    async fn test_l1_cache_operations() {
        let config = CacheConfig::default();
        let cache = CacheSystem::new(config);

        let query = "test query";
        let results = create_test_results();

        // Miss on first access
        assert!(cache.get_query(query).await.is_none());

        // Put and hit
        cache.put_query(query, results.clone()).await;
        assert!(cache.get_query(query).await.is_some());

        // Stats
        let stats = cache.stats().await;
        assert_eq!(stats.l1_query.hits, 1);
        assert_eq!(stats.l1_query.misses, 1);
    }

    #[tokio::test]
    async fn test_l2_cache_operations() {
        let config = CacheConfig::default();
        let cache = CacheSystem::new(config);

        let text = "test text";
        let vector = vec![0.1, 0.2, 0.3];

        // Miss on first access
        assert!(cache.get_embedding(text).await.is_none());

        // Put and hit
        cache.put_embedding(text, vector.clone()).await;
        assert_eq!(cache.get_embedding(text).await.unwrap(), vector);

        // Stats
        let stats = cache.stats().await;
        assert_eq!(stats.l2_embedding.hits, 1);
        assert_eq!(stats.l2_embedding.misses, 1);
    }

    #[tokio::test]
    async fn test_l3_cache_operations() {
        let config = CacheConfig::default();
        let cache = CacheSystem::new(config);

        let chunk_ids = vec![1, 2, 3];
        let bundle = ContextBundle::new();

        // Miss on first access
        assert!(cache.get_context(&chunk_ids).await.is_none());

        // Put and hit
        cache.put_context(&chunk_ids, bundle.clone()).await;
        assert!(cache.get_context(&chunk_ids).await.is_some());

        // Invalidate
        cache.invalidate_context(&chunk_ids).await;
        assert!(cache.get_context(&chunk_ids).await.is_none());

        // Stats
        let stats = cache.stats().await;
        assert_eq!(stats.l3_context.hits, 1);
        assert_eq!(stats.l3_context.misses, 2); // Initial miss + after invalidation
    }

    #[tokio::test]
    async fn test_parse_tree_cache_operations() {
        let config = CacheConfig::default();
        let cache = CacheSystem::new(config);

        let file_path = "test.rs";
        let content_hash = "abc123";
        let tree_data = vec![1, 2, 3, 4, 5];

        // Miss on first access
        assert!(cache
            .get_parse_tree(file_path, content_hash)
            .await
            .is_none());

        // Put and hit
        cache
            .put_parse_tree(file_path, content_hash, tree_data.clone())
            .await;
        assert_eq!(
            cache.get_parse_tree(file_path, content_hash).await.unwrap(),
            tree_data
        );

        // Invalidate
        cache.invalidate_parse_tree(file_path).await;
        assert!(cache
            .get_parse_tree(file_path, content_hash)
            .await
            .is_none());

        // Stats
        let stats = cache.stats().await;
        assert_eq!(stats.parse_tree.hits, 1);
        assert_eq!(stats.parse_tree.misses, 2);
    }

    #[tokio::test]
    async fn test_overall_statistics() {
        let config = CacheConfig::default();
        let cache = CacheSystem::new(config);

        // Generate some cache activity
        cache.put_query("q1", create_test_results()).await;
        cache.get_query("q1").await;
        cache.get_query("q2").await; // Miss

        cache.put_embedding("e1", vec![0.1]).await;
        cache.get_embedding("e1").await;

        let stats = cache.stats().await;

        // Overall hit rate: 2 hits / 3 operations = 0.666...
        // L1: 1 hit (q1), 1 miss (q2) = 2 operations
        // L2: 1 hit (e1), 0 misses = 1 operation
        // Total: 2 hits / 3 operations = 0.666...
        assert!((stats.overall_hit_rate() - 0.666).abs() < 0.02);

        // Total operations across all caches
        assert_eq!(stats.total_operations(), 3);
    }

    #[tokio::test]
    async fn test_clear_all() {
        let config = CacheConfig::default();
        let cache = CacheSystem::new(config);

        // Add entries to all caches
        cache.put_query("q1", create_test_results()).await;
        cache.put_embedding("e1", vec![0.1]).await;
        cache.put_context(&[1, 2, 3], ContextBundle::new()).await;
        cache.put_parse_tree("test.rs", "hash", vec![1, 2, 3]).await;

        // Clear all
        cache.clear_all().await;

        // All should be empty
        assert!(cache.get_query("q1").await.is_none());
        assert!(cache.get_embedding("e1").await.is_none());
        assert!(cache.get_context(&[1, 2, 3]).await.is_none());
        assert!(cache.get_parse_tree("test.rs", "hash").await.is_none());
    }

    #[tokio::test]
    async fn test_disabled_cache_layer() {
        let mut config = CacheConfig::default();
        config.l1_query.enabled = false;

        let cache = CacheSystem::new(config);

        let query = "test";
        let results = create_test_results();

        // Put should be no-op when disabled
        cache.put_query(query, results).await;
        assert!(cache.get_query(query).await.is_none());

        // Stats should remain at zero
        let stats = cache.stats().await;
        assert_eq!(stats.l1_query.hits, 0);
        assert_eq!(stats.l1_query.misses, 0);
    }
}