Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
F

foyer

> 编程语言
Open source

Hybrid in-memory and disk cache in Rust

1.8K stars0 likes1 views
WebsiteGitHub

About

Hybrid in-memory and disk cache in Rust

</a>
<a href="https://docs.rs/foyer">
    
</a>

foyer

foyer aims to be an efficient and user-friendly hybrid cache lib in Rust.

foyer draws inspiration from Facebook/CacheLib, a highly-regarded hybrid cache library written in C++, and ben-manes/caffeine, a popular Java caching library, among other projects.

However, foyer is more than just a rewrite in Rust effort; it introduces a variety of new and optimized features.

API Docs | Crate

Features

  • Hybrid Cache: Seamlessly integrates both in-memory and disk cache for optimal performance and flexibility.
  • Plug-and-Play Algorithms: Empowers users with easily replaceable caching algorithms, ensuring adaptability to diverse use cases.
  • Fearless Concurrency: Built to handle high concurrency with robust thread-safe mechanisms, guaranteeing reliable performance under heavy loads.
  • Zero-Copy In-Memory Cache Abstraction: Leveraging Rust's robust type system, the in-memory cache in foyer achieves a better performance with zero-copy abstraction.
  • User-Friendly Interface: Offers a simple and intuitive API, making cache integration effortless and accessible for developers of all levels.
  • Out-of-the-Box Observability: Integrate popular observation systems such as Prometheus, Grafana, Opentelemetry, and Jaeger in just ONE line.

Projects Using foyer

Feel free to open a PR and add your projects here:

  • RisingWave: SQL stream processing, analytics, and management.
  • Chroma: Embedding database for LLM apps.
  • SlateDB: A cloud native embedded storage engine built on object storage.
  • ZeroFS: File systems and block devices on S3 storage.
  • Percas: A distributed persistent cache service optimized for high performance NVMe SSD.
  • dna: The fastest platform to build production-grade indexers that connect onchain data to web2 services.
  • si: The System Initiative software.
  • AntTP: Serves Autonomi Network data over HTTP protocol.
  • Cachey: Read-through cache for object storage.

Quick Start

To use foyer in your project, add this line to the dependencies section of Cargo.toml.

toml
foyer = "0.22"

If your project is using the nightly rust toolchain, the nightly feature needs to be enabled.

toml
foyer = { version = "0.22", features = ["nightly"] }

Out-of-the-box In-memory Cache

The in-memory cache setup is extremely easy and can be setup in at least 1 line.

rust
use foyer::{Cache, CacheBuilder};

let cache: Cache<String, String> = CacheBuilder::new(16).build();

let entry = cache.insert("hello".to_string(), "world".to_string());
let e = cache.get("hello").unwrap();

assert_eq!(entry.value(), e.value());

Easy-to-use Hybrid Cache

The setup of a hybrid cache is extremely easy.

…

Fully Configured Hybrid Cache

Here is an example of a hybrid cache setup with almost all configurations to show the possibilities of tuning.

…

serde Support

foyer needs to serialize/deserialize entries between memory and disk with hybrid cache. Cached keys and values need to implement the Code trait when using hybrid cache.

The Code trait has already been implemented for general types, such as:

  • Numeric types: u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize, f32, f64.
  • Buffer: Vec<u8>.
  • String: String.
  • Other general types: bool.

For more complex types, you need to implement the Code trait yourself.

To make things easier, foyer provides support for the serde ecosystem. Types implement serde::Serialize and serde::DeserializeOwned, foyer will automatically implement the Code trait. This feature requires enabling the serde feature for foyer.

toml
foyer = { version = "*", features = ["serde"] }

Other Examples

  • Serialize/Deserialize w/wo serde
  • Export Metrics with prometheus and hyper
  • Tail-based Tracing

More code examples and details can be found here.

Supported Rust Versions

foyer is built against the recent stable release. The minimum supported version is 1.91.0. The current foyer version is not guaranteed to build on Rust versions earlier than the minimum supported version.

Supported Platforms

foyer is designed to serve on Linux OS, but can still be built on other OS for development.

However, other components may not support non-Linux OS.

Component Linux MacOS Windows
foyer ✓ ✓ ✓
foyer-bench ✓ ✗ ✗

Development State & Roadmap

Currently, foyer is still under heavy development.

The development state and the roadmap can be found in foyer - Development Roadmap.

Contributing

Contributions for foyer are warmly welcomed!

Don't forget to pass cargo x --fast (which runs most necessary checks and tests) locally before submitting a PR.

If you want to run a broader range of checks locally, run cargo x.

Thank you for your contribution

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rustcachehybrid-cacherust

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言