Memcached is a high-performance, distributed memory object caching system. It is simpler than Redis. It does arguably one thing: Key-Value caching of strings/objects in RAM.
Multi-Threaded: Memcached is multi-threaded (Redis is single-threaded). It scales vertically better on massive multicore machines for simple GET/SET throughput.
Memcached manages memory in "Classes" of chunks (Slabs) to prevent fragmentation.
Memcached通过将内存划分为不同“类”的块(Slabs)来管理内存,以避免内存碎片。
LRU (Least Recently Used)
LRU(最近最少使用)
When full, it evicts the oldest unused items.
当内存已满时,它会淘汰最久未被使用的条目。
No Persistence
无持久化特性
If you restart, data is gone.
重启服务后,所有数据都会丢失。
Best Practices (2025)
2025年最佳实践
Do:
Use for huge read-heavy loads: Facebook uses it heavily.
Use Serialization: Store Protobuf or msgpack for efficiency.
Don't:
Don't use as a Datastore: It is a cache only.
Don't use iterating: You cannot "List all keys". You must know the key to get the value.
Comparison to Redis: In 2025, Redis is generally preferred for features. Use Memcached if you specifically need multi-threaded scaling for pure String caching.