Middleware (1) distributed cache and middleware Cache
Cache is generally used to improve website performance. cached data sources include databases and external interfaces. cache is generally divided into two types: local cache and distributed cache, here we mainly summarize the distributed cache.
Memcached vs Redis
The most commonly used distributed cache is Redis and Memcached, which are one of the most common distributed cache technologies. Most developers may have heard of or come into contact with it, however, few seriously analyze the differences between them and their application scenarios.
Memcached is a comparison between Memcached and Memcached from the following aspects.
Network I/O model
Memcached is multi-thread processing.
Redis is processed in a single thread.
Memory Management Mechanism
Memcached uses a pre-allocated memory pool.
Redis is the way to apply for memory on site.
Supported Data Types
Memcached only supports key/value.
In addition to key/value, Redis also supports list, set, sorted Set, and Hash. Redis supports more data types.
Persistence
Memcached does not support persistence.
Redis supports persistence. There are two persistence policies: Based on RDB snapshots and AOF logs.
Cluster
Both Memcached and Redis support cluster deployment.
Performance
Because Memcached uses multiple threads, its overall performance is superior to that of Redis.
Application scenarios
Through the comparison above, we can basically determine their application scenarios:
1. Both Memcached and Redis can be used as one of the distributed cache implementation technologies.
2. If you want to support more data types except key/value, select Redis.
3. To support data persistence, select Redis.
4. If you have high requirements on Cache performance, consider Memcached.