pub struct S3FIFOCache<K, V>{ /* private fields */ }Expand description
A cache implementation based on the S3-FIFO (Simple Scalable Static FIFO) algorithm.
S3-FIFO uses a three-queue architecture to achieve high hit rates by separating transient “one-hit wonders” from frequently accessed data.
§Architecture
- Small Queue: An intake FIFO for new entries (probationary area).
- Main Queue: A FIFO for entries that have proven their value (protected area).
- Ghost Queue: Tracks hashes of recently evicted items to facilitate re-insertion directly into the Main Queue.
Implementations§
Source§impl<K, V> S3FIFOCache<K, V>
impl<K, V> S3FIFOCache<K, V>
Sourcepub fn new(
capacity: usize,
backoff_config: BackoffConfig,
metrics_config: MetricsConfig,
) -> Self
pub fn new( capacity: usize, backoff_config: BackoffConfig, metrics_config: MetricsConfig, ) -> Self
Creates a new S3Cache with the specified capacity.
The total capacity is partitioned between a 10% small probationary segment and a 90% main protected segment. All slots are initialized as empty and their indices are added to the available pool.
Sourcepub fn get<Q>(&self, key: &Q) -> Option<Ref<K, V>>
pub fn get<Q>(&self, key: &Q) -> Option<Ref<K, V>>
Retrieves a reference to an entry associated with the provided key.
If the entry exists and is valid, its access frequency is atomically incremented. This protects the entry from being removed during the next space-reclamation cycle.
Sourcepub fn insert_with(
&self,
key: K,
value: V,
expired_at: Option<Instant>,
admission: impl Fn(&K, &K) -> bool,
)
pub fn insert_with( &self, key: K, value: V, expired_at: Option<Instant>, admission: impl Fn(&K, &K) -> bool, )
Handles the admission of new entries into the probationary segment.
If the segment is full, this function triggers space reclamation. The entry is stored in a slot obtained from the available pool and then appended to the small queue.