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.
- 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.
- 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.
- Eviction
Config - Eviction algorithm config.
- Fetch
Target - The target of a fetch operation.
- GetOr
Fetch - 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.
- Optional
Fetch - An optional fetch operation that may return
Noneif the entry is not found. - Optional
Fetch Builder - A builder for an optional fetch operation.
- Required
Fetch - A required fetch operation that must return a value.
- Required
Fetch Builder - A builder for a required fetch operation.
- Required
Fetch Builder Erased - A type-erased builder for a required fetch operation.
- Waiter
- A waiter for a fetch operation.