Cachex is an in-memory key/value store for Elixir with optional expirations, limits, transactions, warming, and distribution features.
Overview
Cachex is an Elixir library that provides a fast in-memory key and value store. Features such as time-based expirations, size limits, hooks, cache warming, transactions, async writes, multi-node distribution, filesystem sync, streaming, batching, custom commands, and statistics are all optional and off by default.
You add Cachex as a Mix dependency and start a named cache either with Cachex.start_link in a shell or as a child in an application supervision tree. The Cachex module exposes put, get, exists, delete, and related calls against that registered name.
The API includes bang variants that unwrap ok and error tuples for convenience, though documentation recommends explicit error handling in production. Advanced calls cover batch puts, atomic get-and-update, increment and decrement, lazy fetch when keys are missing, and entries with millisecond expirations.
Guides in the project document batching, local persistence, streaming, limiting cache size, expiring records, statistics, routers, distributed caches, proactive and reactive warming, custom commands, and execution lifecycle hooks.
Key features
- In-memory key-value cache
- Optional TTL expirations
- Maximum size protection
- Transactions and row locking
- Async and batched writes
- Distribution across nodes
- Proactive and reactive warming
- Statistics gathering
Use cases
- Application-level caching in Elixir
- Lazy-computed cache entries
- Shared caches across BEAM nodes