Micro Moka
Micro Moka is a lightweight, single-threaded cache library for Rust. It is a fork of Mini Moka, stripped down to the bare essentials while keeping the W-TinyLFU eviction policy.
Micro Moka provides a non-thread-safe cache implementation for single thread applications.
All caches perform a best-effort bounding of a hash map using an entry replacement algorithm to determine which entries to evict when the capacity is exceeded.
Features
- A cache can be bounded by the maximum number of entries.
- 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.
Change Log
Table of Contents
Usage
Add this to your Cargo.toml:
[]
= "0.1"
Example: Basic Usage
Cache entries are manually added using insert method, and are stored in the cache
until either evicted or manually invalidated.
use Cache;
Minimum Supported Rust Versions
Micro Moka's minimum supported Rust versions (MSRV) are the followings:
| Feature | MSRV |
|---|---|
| default features | Rust 1.76.0 (Feb 8, 2024) |
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, MSRV might be updated more frequently, up to the latest stable. In both cases, increasing MSRV is not considered a semver-breaking change.
Developing Micro Moka
Running All Tests
To run all tests including doc tests on the README, use the following command:
$ RUSTFLAGS='--cfg trybuild' cargo test --all-features
Generating the Doc
$ cargo +nightly -Z unstable-options --config 'build.rustdocflags="--cfg docsrs"' \
doc --no-deps
Credits
Caffeine
Micro Moka's architecture is heavily inspired by the Caffeine library for Java. Thanks go to Ben Manes and all contributors of Caffeine.
License
Micro Moka is distributed under either of
- The MIT license
- The Apache License (Version 2.0)
at your option.
See LICENSE-MIT and LICENSE-APACHE for details.