1. What is memcached
memcached is a high-performance distributed memory object caching system for dynamic web App to reduce database tutorial load. It delivers the speed of dynamic, database-driven websites by caching data and objects in memory to reduce the number of database reads.
I believe many people have used cache, and it is also built-in in .net Caching mechanism, there are many third-party tools such as apache, nginx etc. can be used to cache static resources. At the same time, we can also develop our own caching mechanism to cache database query data to reduce frequent operations on the database. But many times we always feel that these caches are always unsatisfactory. memcached can solve a lot of your troubles. At least it solved a lot of my problems in my study, so I decided to record it and share it.
memcachedhashmap/ value pair 🎜>. The 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 via the memcached protocol. But these things may be too advanced, so we won’t study them for now.
2. Distributed Cache
In fact, memcached is a distributed cache data service, but each service does not communicate with each other at all. This may be a little different from the distributed one I understand. It may be due to my lack of knowledge, or it may be everyone’s thinking. The angle of the problem is different. memcached The client uses a distributed algorithm to save data to different memcached servers and cache the data. Distributed cache, it can be known that memcached can cache large amounts of data. This can make up for the problem that many of us have encountered before: caching data on the application server, and only a small amount of data can be cached, otherwise the impact on the application server will be very large.
memcachedApplication Mechanism Diagram:
This picture is a bit crude, but the problem can still be described clearly. The basic principle of the caching mechanism is to first query the data and save it to memcached. The address is in This request fetches data directly from the memcached cache, thus reducing the request pressure on the server.
1 2 3