Memcached
medium 30 minMemcached is a small, fast, shared cache for plain values.
Remember it
The few things worth knowing cold, and how to make them stick.
Memory hook
Fixed cups, independent trays, and a hen that can lay more.
Egg trays with fixed cup sizes. An egg takes the smallest cup it fits, a full tray gives up its own oldest egg, and a dropped tray is refilled from the hen.
Cheat sheet
- Port
- TCP 11211, UDP off
- Memory -m
- 64 MB default
- Item -I
- 1 MB default
- Key
- 250 bytes
- Threads -t
- 4 default
- Connections -c
- 1,024 default
- Growth -f
- 1.25
- First chunks
- 96, 120, 152, 192
- TTL limit
- 30 days, then a date
- Item overhead
- 48 B, 56 with CAS
Spot it when you see
- Only get, set and delete.
- Values that can always be rebuilt.
- Many small objects and many cores.
Tricks that stick
- add is a lock, cas is a compare.
- Delete, do not update.
- Own class, own evictions.
- More servers, same number of requests.
Do not forget
- Hash modulo N.
- A TTL above 30 days.
- noreply where the answer matters.
- An open port.
- A database that cannot survive an empty cache.