1. What is memcached?
Memcached is a high-performance distributed memory object Cache System for dynamic web applications to reduce the database tutorial load. It caches data and objects in the memory to reduce the number of times the database is read, so as to provide dynamic, database-driven website speed.
I believe many people have used the cache. net also has a built-in cache mechanism, and many third-party tools such as apache and nginx can cache static resources. At the same time, we can also develop our own cache mechanism, cache the data queried by the database to reduce frequent operations on the database. However, we often feel that these caches are not satisfactory. memcached can solve many of your troubles. At least I solved a lot of problems in my studies, so I decided to record them and share them.
Memcached is based on a hashmap that stores key/value pairs. Its daemon is written in c, but the client can be written in any language (this article uses c # as an example) and communicates with the daemon through the memcached protocol. However, these things are too advanced. We will not study them for the moment.
Ii. distributed cache
In fact, memcached serves as a distributed cache data service, but each service does not communicate with each other at all. Here, it may be a little different from what I understand in distributed architecture. It may be that I am not familiar with it, it may also be that everyone thinks differently. The memcached client saves data to different memcached servers through a distributed algorithm and caches the data. Distributed cache, but we know that memcached can cache large amounts of data. This can make up for what we have encountered before to cache data on the application server, and only a small amount of data can be cached, otherwise it will have a huge impact on the application server.
Memcached application mechanism diagram:
This figure is a bit simple, but the problem can still be clearly described. The basic principle of the cache mechanism is to first query data and save it to memcached, the address directly retrieves data from the memcached cache for this request, which reduces the load on server requests.
1 2 3