Skip to content

jmorerice/rusty-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

rusty-cache

πŸ¦€ A bounded, in-memory cache written in Rust with configurable eviction policies (LRU, FIFO, LFU), optional TTL expiration, and thread safety.


πŸ“¦ Features

  • πŸ’» Simple API: put, get, evict, clear
  • πŸ” Eviction Policies: Pluggable strategies (LRU, FIFO, LFU)
  • βš™οΈ Custom Bounded Size: Limit cache by item count (or memory usage, optional)
  • ⏳ TTL Support: Optional time-to-live expiration per entry
  • 🧡 + πŸ” Thread-Safety: Safe across threads and concurrent access using locking
  • πŸͺ΅ Eviction Hooks: Optional callbacks/logging for evicted items
  • 🧱 Extensible: Easily add metrics, serialization, or fallback to external storage

πŸ’‘ Usage Example

use rust_evicting_cache::Cache;

fn main() {
    let mut cache = Cache::new(3);

    cache.put("a", 1);
    cache.put("b", 2);
    cache.put("c", 3);

    println!("{:?}", cache.get(&"a")); // Some(1)

    cache.put("d", 4); // Triggers eviction if capacity exceeded

    println!("{:?}", cache.get(&"b")); // May be None if evicted
}

πŸ”§ Build & Run

git clone https://github.com/your-username/rust-evicting-cache
cd rust-evicting-cache
cargo run       # if you include a main.rs
cargo test      # to run unit tests

πŸ—ΊοΈ Roadmap

  • Base cache with fixed capacity βœ…
  • Add LRU policy βœ…
  • Add FIFO / LFU policy
  • TTL support with background cleanup
  • Eviction callbacks/logging
  • Thread-safe implementation
  • Optional benchmarking

πŸ§‘β€πŸ’» Built With

  • Rust
  • HashMap, RwLock, dashmap, chrono
  • Testing via cargo test

πŸ“˜ Summary

This project demonstrates key systems programming concepts in Rust, including:

  • Ownership and borrowing
  • Concurrency and locking
  • Trait-based design patterns
  • TTL expiration and cleanup logic

Originally inspired by cache problems discussed in distributed systems, backend engineering, and performance-critical settings.

About

Bounded In-Memory Cache with Eviction Policy

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages