Caching and buffering


The idea of caching has a long history. Simply put, the purpose of caching is to save the calculation results that need expensive expenses and take them out directly when needed in the future, avoiding double calculation. The essence of all caches is the same. There are countless applications of cache in computers and even the Internet. We all know that CPU cache is a temporary memory between CPU and memory. Its capacity is not large, but its exchange speed is higher than that of memory. CPU puts frequently exchanged data into cache and reads cache directly if necessary in the future, thus avoiding accessing slower memory. Admittedly, although we think the memory speed is very fast, it is still beyond its capacity in front of CPU cache.

Buffer. The original intention of buffering comes from physics, that is, to slow down the impact force. In computer application scenarios, we use its extended meaning to improve the problems caused by different speeds among various components. For example, when writing data in user state address space to disk, obviously the speed of memory is much faster than that of disk, so people design a disk buffer to allow data to flow into the buffer continuously, and then the buffer is responsible for writing the data to disk, so the memory can not work with the slow rhythm of disk, so the disk buffer plays a role in smoothly connecting fast devices and slow devices, in addition, when we watch video online, the meaning of video buffer is the same.

Buffering and buffering have some similarities, for example, they all need a storage area, and their essence is related to speed inconsistency. Even for buffering, if the calculation speed is the same as that of reading the buffering, it is meaningless. However, the cache pays more attention to policy, that is, cache hit rate. If the required data can be found in the cache every time, it is the most ideal result. If the required data cannot be found in the cache every time, the cache will become worthless and the management logic of the cache will add new overhead. Therefore, anyone who uses cache must be aware of the importance of hit rate.