Crate moka

source
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:
  • 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:

NOTE: The following caches have been moved to a separate crate called “mini-moka”.

§Minimum Supported Rust Versions

This crate’s minimum supported Rust versions (MSRV) are the followings:

FeatureMSRV
default featuresRust 1.65.0 (Nov 3, 2022)
futureRust 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§