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:
- Plug-and-Play eviction algorithm with the same abstraction.
- Tracking the real memory usage by the cache. Including both holding by the cache and by the external users.
- 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:
- record : Carries the cached entry, reference count, pointer links in the eviction container, etc.
- indexer : Indexes cached keys to the records.
- 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§
- Cache
Builder - In-memory cache builder.
- Cache
Properties - Entry properties for in-memory only cache.
- Fetch
Context - Context for fetch calls.
- Fifo
Config - 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.
- Random
State - 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. - S3Fifo
Config - S3Fifo eviction algorithm config.
Enums§
- Cache
- In-memory cache with plug-and-play algorithms.
- Cache
Entry - A cached entry holder of the in-memory cache.
- Error
- In-memory cache error.
- Eviction
Config - Eviction algorithm config.
- Fetch
- A future that is used to get entry value from the remote storage for the in-memory cache.
- Fetch
State - 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.