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§

CacheBuilder
In-memory cache builder.
CacheProperties
Entry properties for in-memory only cache.
FetchContext
Context for fetch calls.
FifoConfig
Fifo eviction algorithm config.
LfuConfig
w-TinyLFU eviction algorithm config.
LruConfig
Lru eviction algorithm config.
Piece
A piece of record that is irrelevant to the eviction algorithm.
RandomState
Provides a Hasher factory. This is typically used (e.g. by HashMap) to create AHashers in order to hash the keys of the map. See build_hasher below.
S3FifoConfig
S3Fifo eviction algorithm config.

Enums§

Cache
In-memory cache with plug-and-play algorithms.
CacheEntry
A cached entry holder of the in-memory cache.
Error
In-memory cache error.
EvictionConfig
Eviction algorithm config.
Fetch
A future that is used to get entry value from the remote storage for the in-memory cache.
FetchState
The state of fetch.
Op
Wrapper for one of the three kind of operations for the eviction container:

Traits§

Eviction
Cache eviction algorithm abstraction.
Pipe
Pipe is used to notify disk cache to cache entries from the in-memory cache.
Weighter
The weighter for the in-memory cache.

Type Aliases§

Result
In-memory cache result.