| Crates.io | search_engine_cache |
| lib.rs | search_engine_cache |
| version | 0.1.3 |
| created_at | 2025-12-12 17:03:54.578069+00 |
| updated_at | 2025-12-13 08:25:51.285214+00 |
| description | Implementation of various caching algorithms like Landlord,weighted LFU and LRU commonly used in search engines |
| homepage | |
| repository | https://github.com/kev1N916/search_engine_cache |
| max_upload_size | |
| id | 1981877 |
| size | 35,116 |
A high-performance collection of cache implementations in Rust, featuring LRU, LFU, and Landlord eviction policies.
Evicts the least recently accessed items first. Perfect for general-purpose caching where recent access patterns predict future access.
Use when:
Evicts items based on access frequency, with optional weighted support for priority-based eviction.
Use when:
A weight-based cache with dynamic priority updates. Priority increases on access and items are evicted based on lowest priority.
Use when:
Add this to your Cargo.toml:
[dependencies]
search_engine_cache = "0.1.0"
use search_engine_cache::lru::LRUCache;
fn main() {
let mut cache = LRUCache::new(3);
cache.put(1, "apple");
cache.put(2, "banana");
cache.put(3, "cherry");
// Access an item (makes it "recently used")
cache.get(&1);
// Adding a 4th item evicts the least recently used (key 2)
cache.put(4, "date");
assert_eq!(cache.get(&2), None); // Evicted
assert_eq!(cache.get(&1), Some(&"apple")); // Still present
}
use search_engine_cache::lfu_w::LFUCache;
fn main() {
let mut cache = LFUCache::new(3, false);
cache.put(1, "apple", None);
cache.put(2, "banana", None);
cache.put(3, "cherry", None);
// Access item 1 multiple times (increases frequency)
cache.get(&1);
cache.get(&1);
cache.get(&1);
// Access item 2 once
cache.get(&2);
// Adding a 4th item evicts the least frequent (key 3)
cache.put(4, "date", None);
assert_eq!(cache.get(&3), None); // Evicted (freq=1)
assert_eq!(cache.get(&1), Some(&"apple")); // Safe (freq=4)
}