Crate foyer_memory

Source
Expand description

This crate provides a concurrent in-memory cache component that supports replaceable eviction algorithm.

§Motivation

There are a few goals to achieve with the crate:

  1. Plug-and-Play eviction algorithm with the same abstraction.
  2. Tracking the real memory usage by the cache. Including both holding by the cache and by the external users.
  3. Reduce the concurrent read-through requests into one.

To achieve them, the crate needs to combine the advantages of the implementations of RocksDB and CacheLib.

§Components

The cache is mainly composed of the following components:

  1. record : Carries the cached entry, reference count, pointer links in the eviction container, etc.
  2. indexer : Indexes cached keys to the records.
  3. eviction container : Defines the order of eviction. Usually implemented with intrusive data structures.

Because a record needs to be referenced and mutated by both the indexer and the eviction container in the same thread, it is hard to implement in 100% safe Rust without overhead. So, accessing the algorithm managed per-entry state requires operation on the UnsafeCell.

Structs§

Enums§

  • In-memory cache with plug-and-play algorithms.
  • A cached entry holder of the in-memory cache.
  • Hint for the cache eviction algorithm to decide the priority of the specific entry if needed.
  • In-memory cache error.
  • Eviction algorithm config.
  • A future that is used to get entry value from the remote storage for the in-memory cache.
  • The state of [Fetch].
  • Wrapper for one of the three kind of operations for the eviction container:

Traits§

  • Cache eviction algorithm abstraction.
  • The weighter for the in-memory cache.

Type Aliases§