Skip to content

FAQ

Is Memcached the same as Redis?

No. Both are in-memory key-value stores, but they differ in scope. Memcached is deliberately minimal: multithreaded, cache-only, no persistence. Redis adds persistence, replication, pub/sub, and rich data types (lists, sets, hashes, sorted sets). Memcached is faster per-core for plain key-value; Redis is more versatile. Choose Memcached when you want a pure cache and nothing else.

Does Memcached persist data across restarts?

No. Memcached holds everything in RAM and loses it all on restart. That is by design. If you need data to survive a restart, use Redis with persistence, or a database. Memcached is for the data you can recompute from the source of truth.

How do I choose the TTL for a key?

Match the TTL to how quickly the data changes and how expensive the backend query is. A user profile that changes weekly can have a TTL of hours. A product price that changes daily can have a TTL of minutes. A live stock ticker should not be cached with a TTL at all. The TTL is the interval between "this is fresh" and "this is a stale guess".

What is a cache stampede and how do I prevent it?

A cache stampede happens when a popular key expires and dozens of concurrent requests simultaneously miss, all query the backend, and all write back. The backend is overloaded. Prevent it with a lock (only one request recomputes) or a probabilistic early expiry (expire slightly before the TTL so one request refreshes it before the rest arrive). Facebook's "leases" paper is the standard reference.

Should I use Memcached for session storage?

Usually not, because sessions need to survive a restart and Memcached loses everything. Redis or a database is a safer place for sessions. Memcached can be used for session data if losing sessions on restart is acceptable, but the choice should be made deliberately, not by default.