basic_usage/
basic_usage.rs

1use fifo_cache::FifoCache;
2use std::time::Duration;
3
4fn main() {
5  // Create a cache with capacity 1000 and 5-minute TTL
6  let mut cache = FifoCache::new(1000, Duration::from_secs(300));
7  
8  // Insert some values
9  cache.insert("user:123", "John Doe");
10  cache.insert("user:456", "Jane Smith");
11  cache.insert("config:timeout", "30");
12  
13  // Retrieve values
14  if let Some(name) = cache.get(&"user:123") {
15    println!("Found user: {}", name);
16  }
17  
18  // Cache will automatically evict oldest entries when full
19  // and expire entries after 5 minutes
20  
21  println!("Cache size: {}/{}", cache.len(), cache.max_size());
22  
23  // Manual cleanup of expired entries
24  cache.cleanup_expired();
25}