Expand description
Moka is a fast, concurrent cache library for Rust. Moka is inspired by the Caffeine library for Java.
Moka provides in-memory concurrent cache implementations on top of hash maps. They support full concurrency of retrievals and a high expected concurrency for updates. They utilize a lock-free concurrent hash table as the central key-value storage.
All cache implementations perform a best-effort bounding of the map using an entry replacement algorithm to determine which entries to evict when the capacity is exceeded.
§Features
- Thread-safe, highly concurrent in-memory cache implementations:
- Synchronous caches that can be shared across OS threads.
- An asynchronous (futures aware) cache.
- A cache can be bounded by one of the followings:
- The maximum number of entries.
- The total weighted size of entries. (Size aware eviction)
- Maintains near optimal hit ratio by using an entry replacement algorithms
inspired by Caffeine:
- Admission to a cache is controlled by the Least Frequently Used (LFU) policy.
- Eviction from a cache is controlled by the Least Recently Used (LRU) policy.
- More details and some benchmark results are available here.
- Supports expiration policies:
- Time to live.
- Time to idle.
- Per-entry variable expiration.
- Supports eviction listener, a callback function that will be called when an entry is removed from the cache.
§Examples
See the following document:
- Thread-safe, synchronous caches:
- An asynchronous (futures aware) cache:
future::Cache(Requires “future” feature)
NOTE: The following caches have been moved to a separate crate called “mini-moka”.
- Non concurrent cache for single threaded applications:
moka::unsync::Cache→mini_moka::unsync::Cache
- A simple, thread-safe, synchronous cache:
moka::dash::Cache→mini_moka::sync::Cache
§Minimum Supported Rust Versions
This crate’s minimum supported Rust versions (MSRV) are the followings:
| Feature | MSRV |
|---|---|
| default features | Rust 1.65.0 (Nov 3, 2022) |
future | Rust 1.65.0 (Nov 3, 2022) |
It will keep a rolling MSRV policy of at least 6 months. If only the default
features are enabled, MSRV will be updated conservatively. When using other
features, like future, MSRV might be updated more frequently, up to the latest
stable. In both cases, increasing MSRV is not considered a semver-breaking
change.
Re-exports§
Modules§
- Provides a thread-safe, concurrent asynchronous (futures aware) cache implementation.
- Common data types for notifications.
- Cache operations.
Structs§
- A snapshot of a single entry in the cache.
Enums§
- The error type for the functionalities around
Cache::invalidate_entries_ifmethod.