When memcached needs to store new data in memory and the memory is already full, the following will happen:
- memcached searches for a suitable * expired record, and if it is found, it replaces the data in that record. At what answer point 3) the data is not deleted immediately, but when it is necessary to install new data, the space is redistributed.
- If no expired record is found, then the replaced one is used.
* Keep in mind how memcached deals with memory: it allocates blocks of different sizes, so the size of the data that you are going to install in the cache plays a role in determining which record is deleted. Records - 2K, 4K, 8K, 16K ... etc. up to 1M.
All this information is in the documentation so just read it carefully. As @deceze notes, memcached does not guarantee that data will be available in memory, and you should be prepared for a miss schooner. One interesting approach to avoid the storm is to set the expiration time with some random offset, for example, 10 + [0.10] minutes, which means that some items will be saved for 10 and others for 20 minutes (the goal is that not all items expire at the same time).
And if you want to store something in the cache, you need to do two things:
- A warm-up script that requests a cache for loading data. So it's always used recently
- 2 expiration dates for the goods: one real time of expiration, say, after 30 minutes; the other is cached along with the item - the logical expiration time, say, after 10 minutes. When you extract data from the cache, you check the logical expiration time, and if it expired, reload the data and set it in the cache for another 30 minutes. Thus, you will never hit the expiration time of the real cache, and the data will be updated periodically.
5) What is the value of the -k option in "memcached.conf". I'm not able to understand what “Block all memory” means. Also the description in README is also not enough.
No matter how much memory you allocate for memcached, it will only use the right amount, for example. it allocates only used memory. However, with the -k option, all memory is saved when memcached starts, so it always allocates the entire amount of memory, regardless of whether it needs it or not.
Maxim Krizhanovsky
source share