Home > Database > Mysql Tutorial > What are the differences between mysql Cache and Buffer?

What are the differences between mysql Cache and Buffer?

coldplay.xixi
Release: 2020-06-29 10:39:38
Original
2659 people have browsed it

The differences between mysql Cache and Buffer are: 1. Buffer is used to buffer block devices and only records the metadata of the file system, while cached is used to buffer files; 2. Buffer is used to store what is in the directory. Content, permissions, etc., while cached is used to remember open files.

What are the differences between mysql Cache and Buffer?

The difference between mysql Cache and Buffer is:

The core function of Buffer is to Cushioning, softening impact. For example, if you have to write to the hard disk 100 times per second, it will have a great impact on the system and waste a lot of time busy processing the two things of starting and ending writing. Use a buffer to temporarily store it and write to the hard disk every 10 seconds. The impact on the system is very small, the writing efficiency is high, and your life is comfortable. Greatly softened the impact.

The core function of Cache is to speed up access. For example, if you have finished a very complicated calculation and want to use the results next time, just keep the results in an easy-to-reach place so that you don't have to calculate them again next time. Speeds up data retrieval.

So, if you pay attention to the storage system, you will find that the read and write buffer/cache names of the hard disk are different, called write-buffer and read-cache . The difference between the two is clearly stated.

Of course, in many cases, the two may be mixed at a macro level. For example, many people actually use memcached for both reading and writing. Many times the same is true for Non-SQL databases. Strictly speaking, the L2 and L3 Cache in the CPU are also used for both reading and writing - because you cannot simply define whether the CPU uses them to read or write. The hard disk is also a typical example. The buffer and cache are both in the same space. Is it the buffer or the cache?

But think about it carefully, is it okay to use cache as a buffer? Of course, as long as the cache eviction logic can be controlled, there will be no problem.

So what about using the buffer as a cache? It seems that in very special circumstances, when the access sequence can be determined, it is also possible. Just think about it and you will understand - by definition, does the buffer need to be stored randomly? Generally not needed. But cache must be. So most of the time it is OK to use cache instead of buffer, but vice versa is more limiting. This is also technically the key difference between cache and buffer.

Supplement 1:

Don’t misunderstand that Buffer is for writing, and Cache is for reading. Can I use Buffer for reading? Of course you can. For example, if you want to process reads in batches instead of processing them all, you can use the read buffer. Of course, you can also use cache when writing, for example, when your writes are highly random. Which scenario uses Buffer and which scenario uses Cache depends on the specific needs of the scenario.

Supplement 2:

Don’t misunderstand that Cache or Buffer must be memory or something that exists on high-speed media. As long as it's relatively high speed. I can definitely store a cache on the hard disk. For example, some games will create precompiled shaders at runtime (exposing their age). This is essentially a cache that exists on a slow hard disk, because reading the hard disk is still faster than recompiling. quick. The same is true for Buffers. For example, the NTFS file system has its own Logging Buffer, which even explicitly refuses to be placed in any volatile cache.

Related learning recommendations: mysql video tutorial

The above is the detailed content of What are the differences between mysql Cache and Buffer?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template