PROVIDER Β· The classic distributed memory cache
Memcached
Memcached is the earliest widely used distributed memory cache, whose multi-threaded architecture and minimal key-value model deliver high throughput with no learning curve as the standard LAMP cache layer.
4.1pts
Pros
Cons
Product Information
Detailed Notes
Overview
Memcached was created in 2003 by Brad Fitzpatrick for LiveJournal under the BSD licence and became the earliest widely used distributed memory cache, known for a minimal key-value model and multi-threaded architecture as the standard cache layer in LAMP stacks.
For Backend & Database work its role is unambiguous, since it only caches: string and simple structure storage, multi-threaded request handling, and automatic LRU eviction give high performance with almost no learning curve, while distribution comes from client-side hashing so servers need not talk to each other.
The limits are equally clear, because there is no persistence, no rich data structures or transactions, no replication so a restart loses everything, and no native atomic command suite, so ranking, pub/sub, persistence, or vector needs point to Redis or Valkey.
Core Strengths
- Multi-threaded architecture uses many cores with high per-instance throughput
- Minimal implementation and a simple protocol with mature clients in nearly every language
- Automatic LRU eviction with a memory cap keeps usage bounded
- BSD licensing allows free deployment and distribution
Product Ecosystem
Cache model
Key-value storage of serialised objects, commonly caching query results and rendered HTML.
Distribution
Clients map keys by consistent hashing across servers, with cache stampedes to handle on expansion.
Operations
No persistence means a cold start after restart, with hit rate, memory use, and connections the key metrics.
Drawbacks
- No persistence, so a restart wipes the cache and floods the backend
- Simple key-value only without lists, sets, or sorted sets
- No replication or HA, relying on client sharding and multi-write
- No built-in atomics or scripting, forcing multiple round trips
Use Cases
- Caching database query results (β β β β β ) - Simple key-value uses fewest resources
- Session sharing (β β β β ) - Shared state across machines
- Page fragment and object caching (β β β β ) - Serialised storage
- Leaderboards and persistence (β ) - Use Redis or Valkey
Pricing
| Plan | Price | Scope |
|---|---|---|
| Memcached open source | $0 | BSD licensed, self-managed |
| Managed cache services | Per instance-hour | Monitoring and automatic failover |
| Self-built cluster | Server cost | Sharding and monitoring on you |
The software is free with cost in memory and operations, since instance size determines how much data caches, managed plans bill hourly with small instances in the low tens of dollars monthly, and self-hosting means building sharding and monitoring.
FAQ
-
Memcached or Redis? Memcached for pure caching with simplicity and multi-threaded throughput, Redis or Valkey for data structures, persistence, pub/sub, and atomics.
-
How are cache stampedes handled? Expiring hot keys surges the backend, addressed with mutex locks, staggered expiry times, or logical expiry with background refresh.
-
Can it be a database? No, since no persistence is guaranteed and restarts lose data, so it only accelerates the layer in front of a database.