No-unsafe Rust implementation of thread-safe cache with S3-FIFO eviction policy

4 months ago 3

Crates.io Version docs.rs Continuous Integration

plain-cache is a high-performance, thread-safe cache implementation that makes no use of unsafe Rust code. It implements the S3-FIFO eviction algorithm [see]. plain-cache allocates its capacity at cache instantiation time and is designed for high-throughput scenarios with minimal contention.

  • S3-FIFO eviction: Optimal cache performance with predictable behavior
  • Sharded design: Reduces lock contention for concurrent access
  • Built-in metrics: Track hits, misses, evictions, and timing
  • Custom hashing: Support for different hash functions
  • Memory pre-allocation: Fixed capacity allocated at creation time
  • API simplicity: Straightforward get/insert interface
use plain_cache::Cache; let cache = Cache::with_capacity(1000); cache.insert("key", "value"); assert_eq!(cache.get("key"), Some("value"));
  • High performance
  • Thread safety
  • No usage of unsafe code
  • No background threads
  • Cache metrics
  • Small dependency tree
  • Easy-to-reason cache eviction (S3-FIFO)
  • Ability to provide custom hasher
  • Zero-sized types
  • Lifecycle hooks
  • Item weighing
  • Custom eviction policies
  • Time-based eviction
  • Explicit cache deletions
  • Memory-based capacity limits
  • Cache warming strategies
Read Entire Article