Crate foyer_memory

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.
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.
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.
EvictionConfig
Eviction algorithm config.
FetchTarget
The target of a fetch operation.
GetOrFetch
A future that is used to get entry value from the remote storage for the in-memory cache.
Op
Wrapper for one of the three kind of operations for the eviction container:

Traits§

Eviction
Cache eviction algorithm abstraction.
Filter
The filter for the in-memory cache.
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§

Notifier
A notifier for a fetch operation.
OptionalFetch
An optional fetch operation that may return None if the entry is not found.
OptionalFetchBuilder
A builder for an optional fetch operation.
RequiredFetch
A required fetch operation that must return a value.
RequiredFetchBuilder
A builder for a required fetch operation.
RequiredFetchBuilderErased
A type-erased builder for a required fetch operation.
Waiter
A waiter for a fetch operation.