micro-moka

Crates.iomicro-moka
lib.rsmicro-moka
version0.1.1
created_at2026-01-01 18:33:50.098208+00
updated_at2026-01-01 19:10:58.830438+00
descriptionA lightweight, single-threaded cache library with W-TinyLFU eviction
homepage
repositoryhttps://github.com/user1303836/micro-moka
max_upload_size
id2016939
size116,428
(user1303836)

documentation

https://docs.rs/micro-moka/

README

Micro Moka

GitHub Actions crates.io release docs

license

Micro Moka is a lightweight, single-threaded cache library for Rust. It is a specialized fork of Mini Moka, engineered for use cases where binary size, compile times, and simplicity are paramount, while maintaining the high hit-ratio of 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.

Key Features

  • Minimal Footprint: Stripped of all async, concurrent, and heavy logic. Ideal for CLIs, WASM, and environments where binary size matters.
  • Tiny Dependency Tree: Minimal dependencies (smallvec, tagptr, triomphe). No parking_lot or async runtimes.
  • Smart Eviction: Uses W-TinyLFU (LFU admission + LRU eviction) to maintain a near-optimal hit ratio, significantly outperforming standard LRU caches.
  • Bounded Capacity: Caches are strictly bounded by a maximum number of entries.

Change Log

Table of Contents

Usage

Add this to your Cargo.toml:

[dependencies]
micro_moka = "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 micro_moka::unsync::Cache;

fn main() {
    // Create a cache that can store up to 10,000 entries.
    let mut cache = Cache::new(10_000);

    // Insert an entry.
    cache.insert("my_key", "my_value");

    // Get the entry.
    // get() returns Option<&V>, a reference to the stored value.
    if let Some(value) = cache.get(&"my_key") {
        println!("value: {}", value);
    }

    // Invalidate the entry.
    cache.invalidate(&"my_key");
}

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.

Commit count: 0

cargo fmt