Distributed is the main feature of memcached, so you can install memcached on multiple servers to build a larger cache server. In this way, memcached can help us minimize the database pressure, so that we can build faster and more scalable Web applications. Figure 1 shows how memcache works with the database.
Figure 1: How memcache works with databases
How does memcache work?
Figure 1 shows the process. I believe that anyone who has developed database applications will be familiar with it. Let's explain step by step what happened in the figure:
- Check whether the data requested by the user exists in the cache. If yes, you only need to directly return the requested data, which is totally irrelevant to the database.
- If the requested data cannot be found in the cache, query the database again. When the request data is returned, the data is stored in the cache.
- Keep the cache fresh. When data changes (for example, data is modified or deleted), the cache information must be updated synchronously, make sure that the user does not get the old data in the cache.
Obviously, memcached can play a major role in High-concurrency data queries and massive data output. Because Accessing memory data in memcached is much faster than the disk data in the database.