memcached
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMemcached
Memcached
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.
Memcached是一款高性能的分布式内存对象缓存系统。它比Redis更简单,主要专注于一件事:在内存中对字符串/对象进行键值对缓存。
When to Use
使用场景
- Simple Caching: Pure LRU cache.
- Multi-Threaded: Memcached is multi-threaded (Redis is single-threaded). It scales vertically better on massive multicore machines for simple GET/SET throughput.
- Session Cache: Storing web sessions.
- 简单缓存:纯LRU缓存。
- 多线程架构:Memcached采用多线程设计(Redis为单线程)。在多核服务器上,对于简单的GET/SET操作,它的垂直扩展性能更优。
- 会话缓存:存储Web会话。
Quick Start
快速开始
bash
undefinedbash
undefinedTelnet interface
Telnet接口
set mykey 0 60 4
data
STORED
get mykey
VALUE mykey 0 4
data
END
undefinedset mykey 0 60 4
data
STORED
get mykey
VALUE mykey 0 4
data
END
undefinedCore Concepts
核心概念
Slab Allocation
Slab分配机制
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.
建议:
- 适用于高读负载场景:Facebook大量使用该系统。
- 使用序列化:为提升效率,可存储Protobuf或msgpack格式的数据。
不建议:
- 不要将其用作数据库:它仅作为缓存使用。
- 不要尝试遍历键:你无法“列出所有键”,必须知道具体的键才能获取对应的值。
- 与Redis的对比:在2025年,Redis通常因功能更丰富而更受青睐。如果你的场景仅需针对纯字符串缓存的多线程扩展能力,再选择Memcached。