Skip to main content

Quick start

Add dependencies​

Add feuer to Cargo.toml:

[dependencies]
feuer = "0.1"
bytes = "1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

The disk feature is on by default. If you only want the memory cache, set default-features = false to drop feuer-storage completely (even on Linux).

Memory cache​

This works on Linux, macOS, and Windows:

use std::convert::Infallible;

use bytes::Bytes;
use feuer::Cache;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cache = Cache::builder()
.memory_capacity(64 * 1024 * 1024)
.open()?;

let bytes = cache
.get_or_fetch("object-v1", || async {
// Replace this with your download or computation.
Ok::<_, Infallible>(Bytes::from_static(b"hello world"))
})
.await?;

assert_eq!(bytes.as_ref(), b"hello world");
Ok(())
}
  • get checks memory and disk without calling your fetch callback.
  • insert writes bytes synchronously without needing a Tokio runtime.
  • Cloning a Cache is cheap and shares the same entries and in-flight work across tasks.

Add disk caching on Linux​

Add a disk capacity and directory to enable the SSD tier:

let cache = Cache::builder()
.memory_capacity(64 * 1024 * 1024)
.disk_capacity(1024 * 1024 * 1024)
.directory("feuer_cache")
.open()?;

open() is synchronous and blocks until disk metadata recovery finishes. Each cache locks its own backing file, so set .file_name(...) when putting multiple caches in the same directory.

If you want to fall back to your source when disk reads pile up, use get_or_fetch_with_disk_fallthrough.

Share I/O queues across caches​

If you run multiple caches on the same SSD, share one IoQueues between them so read limits, fall-through, and write throttling apply across the whole drive:

use feuer::{Cache, IoQueues, IoQueuesConfig};

let io_queues = IoQueues::with_config(IoQueuesConfig {
fallthrough_waiters: 64,
})?;

let splits = Cache::builder()
.directory("feuer_cache")
.file_name("splits")
.memory_capacity(64 << 20)
.disk_capacity(2 << 30)
.with_io_queues(io_queues.clone())
.open()?;

let predicates = Cache::builder()
.directory("feuer_cache")
.file_name("predicates")
.memory_capacity(32 << 20)
.disk_capacity(1 << 30)
.with_io_queues(io_queues)
.open()?;

See the full shared I/O queues example.

Platform support and requirements​

Feuer needs Rust 1.91.0 or newer (edition 2024).

FeatureLinuxmacOSWindows
Memory cacheYesYesYes
Disk cache (io_uring + O_DIRECT)Yes——

Disk caching needs Linux, a Tokio runtime for background workers, io_uring, and a filesystem that supports O_DIRECT and STATX_DIOALIGN. If you run in containers, make sure seccomp allows io_uring.

Keys and recovery​

Lookups take any borrowed Hash key (strings, tuples, structs). Feuer hashes keys with SipHash-1-3-128 using a random secret key per cache (saved in the disk header) and stores only the hash.

  • Objects are immutable and there is no delete or invalidation API. Use a new key if the bytes change.
  • Bump .payload_version(n) (or FEUER_PAYLOAD_VERSION) when you change your payload format or key hashing, so old disk entries get cleared on open.
  • Disk writes and recovery are best-effort. Your source still needs to serve objects after eviction or a restart.

Next: Disk I/O, Eviction and admission, Observability, key hashing, disk format, or the API docs.