foyer_memory/lib.rs
1// Copyright 2025 foyer Project Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! This crate provides a concurrent in-memory cache component that supports replaceable eviction algorithm.
16//!
17//! # Motivation
18//!
19//! There are a few goals to achieve with the crate:
20//!
21//! 1. Plug-and-Play eviction algorithm with the same abstraction.
22//! 2. Tracking the real memory usage by the cache. Including both holding by the cache and by the external users.
23//! 3. Reduce the concurrent read-through requests into one.
24//!
25//! To achieve them, the crate needs to combine the advantages of the implementations of RocksDB and CacheLib.
26//!
27//! # Components
28//!
29//! The cache is mainly composed of the following components:
30//! 1. record : Carries the cached entry, reference count, pointer links in the eviction container, etc.
31//! 2. indexer : Indexes cached keys to the records.
32//! 3. eviction container : Defines the order of eviction. Usually implemented with intrusive data structures.
33//!
34//! Because a record needs to be referenced and mutated by both the indexer and the eviction container in the same
35//! thread, it is hard to implement in 100% safe Rust without overhead. So, accessing the algorithm managed per-entry
36//! state requires operation on the `UnsafeCell`.
37
38mod cache;
39mod error;
40mod eviction;
41mod indexer;
42mod pipe;
43mod raw;
44mod record;
45
46mod prelude;
47pub use prelude::*;
48
49#[cfg(any(test, feature = "test_utils"))]
50pub mod test_utils;