|
266 | 266 | //! // Touch to mark as recently used without retrieving |
267 | 267 | //! concurrent_cache.touch(&2); |
268 | 268 | //! |
269 | | -//! // Type aliases for common patterns |
270 | | -//! use crate::storage::disk::async_disk::cache::lru::BufferPoolCache; |
| 269 | +//! // Type alias for a concurrent page cache using this policy |
| 270 | +//! type BufferPoolCache<V> = ConcurrentLruCache<u64, V>; |
271 | 271 | //! let page_cache: BufferPoolCache<Vec<u8>> = BufferPoolCache::new(256); |
272 | 272 | //! ``` |
273 | 273 | //! |
@@ -3757,20 +3757,20 @@ mod tests { |
3757 | 3757 | assert_eq!(cache.recency_rank(&3), Some(0)); // New head |
3758 | 3758 | assert_eq!(cache.recency_rank(&1), Some(1)); // Old item is tail |
3759 | 3759 |
|
3760 | | - // Test insertion with available capacity (cache capacity is 3, we have 2 items) |
| 3760 | + // Test insertion when there is still available capacity (cache capacity is 3, we currently have 2 items) |
3761 | 3761 | cache.insert(4, Arc::new(400)); |
3762 | | - assert_eq!(cache.len(), 3); // Should be 3 items now (1, 3, 4) |
3763 | | - assert!(cache.contains(&1)); // Should still be present |
| 3762 | + assert_eq!(cache.len(), 3); // Cache should now be at full capacity |
| 3763 | + assert!(cache.contains(&1)); // Key 1 is expected to be present before any further evictions |
3764 | 3764 | assert!(cache.contains(&3)); |
3765 | 3765 | assert!(cache.contains(&4)); |
3766 | 3766 | assert_eq!(cache.recency_rank(&4), Some(0)); // Most recent |
3767 | 3767 | assert_eq!(cache.recency_rank(&3), Some(1)); // Previous head |
3768 | 3768 | assert_eq!(cache.recency_rank(&1), Some(2)); // Least recent (tail) |
3769 | 3769 |
|
3770 | | - // Now test eviction by inserting another item (5th item, exceeds capacity) |
| 3770 | + // Now test eviction by inserting another item (5th distinct key, exceeds capacity) |
3771 | 3771 | cache.insert(5, Arc::new(500)); |
3772 | | - assert_eq!(cache.len(), 3); // Should maintain capacity |
3773 | | - assert!(!cache.contains(&1)); // LRU evicted |
| 3772 | + assert_eq!(cache.len(), 3); // Cache should remain at its maximum capacity |
| 3773 | + assert!(!cache.contains(&1)); // LRU (key 1) should be evicted at this point |
3774 | 3774 | assert!(cache.contains(&3)); |
3775 | 3775 | assert!(cache.contains(&4)); |
3776 | 3776 | assert!(cache.contains(&5)); |
@@ -4569,7 +4569,7 @@ mod tests { |
4569 | 4569 | break; |
4570 | 4570 | } |
4571 | 4571 | } |
4572 | | - if !found_rank && i < cache.len() { |
| 4572 | + if !found_rank { |
4573 | 4573 | // This should not happen in correct LRU implementation |
4574 | 4574 | panic!("Missing rank {} in steady state", i); |
4575 | 4575 | } |
|
0 commit comments