NotesSystem

Memcached

Also: memcache

A deliberately simple, multithreaded, in-memory key-value cache with no persistence, no replication and no rich types, which leaves distribution to the clients. That simplicity is why it scales to the largest cache fleets in the world.

Also in: Caching › In the real world

Design choices

  • Caching: keys hash to servers on the client side (or via a router such as mcrouter), and servers don't talk to each other. Memory comes from a slab allocator with fixed-size chunk classes, which avoids fragmentation over time at the cost of some wasted space per item.
  • Cache Eviction Policy: since 1.5, a segmented LRU (hot, warm and cold queues). An item must be hit twice to be protected, which resists scans. Extstore can push values to flash and keep keys in RAM.
  • Cache-Aside: the canonical look-aside cache. Facebook's deployment invalidates with deletes driven by the MySQL commit log.
  • Cache Stampede: Facebook extended it with leases, which cap refills to one client per key per 10 s.

Notable trade-offs

  • No persistence or replication: a restarted node comes back empty, so a cold cache is a capacity event you must plan for (gutter pools, warm-up from peers).
  • Only strings and bytes: no server-side data structures, unlike Redis.