Memcached
Memcached is an open-source, high-performance, distributed in-memory key-value cache, originally designed to speed up dynamic web applications by reducing database load. It is one of the oldest and most widely deployed caching systems, often paired with relational databases for read-heavy workloads.
How it works
Memcached stores arbitrary string keys mapped to arbitrary byte values, with a per-entry TTL. The protocol is intentionally simple: get, set, add, delete, incr, decr. There is no built-in clustering; instead, clients hash keys (typically with consistent hashing) to distribute them across many Memcached nodes.
Memcached uses a slab allocator to avoid memory fragmentation: memory is divided into chunks of fixed sizes, and items are placed in the slab whose chunk size best fits.
Memcached vs Redis
- Memcached. Pure cache. Simple. Multi-threaded. No persistence. Values are opaque bytes.
- Redis. Cache plus rich data structures (lists, sets, sorted sets, streams), persistence, replication, pub/sub. Single-threaded command loop. Wider operational surface.