What is Caching and how it works?
"๐ง๐ต๐ฒ๐ฟ๐ฒ ๐ฎ๐ฟ๐ฒ ๐ผ๐ป๐น๐ ๐๐๐ผ ๐ต๐ฎ๐ฟ๐ฑ ๐๐ต๐ถ๐ป๐ด๐ ๐ถ๐ป ๐๐ผ๐บ๐ฝ๐๐๐ฒ๐ฟ ๐ฆ๐ฐ๐ถ๐ฒ๐ป๐ฐ๐ฒ: ๐ฐ๐ฎ๐ฐ๐ต๐ฒ ๐ถ๐ป๐๐ฎ๐น๐ถ๐ฑ๐ฎ๐๐ถ๐ผ๐ป ๐ฎ๐ป๐ฑ ๐ป๐ฎ๐บ๐ถ๐ป๐ด ๐๐ต๐ถ๐ป๐ด๐.โ - Phil Karlton
๐๐ฎ๐ฐ๐ต๐ถ๐ป๐ด
The primary function of a cache is to increase data retrieval performance by reducing the need to access the storage in the backend.
Caches take advantage of the locality of reference principle thatย "recently requested data is likely to be requested again".
๐๐ฎ๐ฐ๐ต๐ฒ ๐ต๐ถ๐
A cache hit describes the situation where content is successfully served from the cache. The tags are searched in the memory rapidly, and when the data is found and read, it's considered a cache hit.
๐๐ฎ๐ฐ๐ต๐ฒ ๐บ๐ถ๐๐
A cache miss refers to the instance when the memory is searched, and the data isn't found. When this happens, the content is transferred and written into the cache.
๐๐ฎ๐ฐ๐ต๐ฒ ๐ถ๐ป๐๐ฎ๐น๐ถ๐ฑ๐ฎ๐๐ถ๐ผ๐ป is a process where the computer system declares the cache entries as invalid, as a result it removes the caches or replaces them. If the data in the system is changed, the cache should be invalidated. If this is not done, it can cause inconsistent application behaviour.
In our next post, we will go deeper into Caching and discuss write-through caching, write-around caching, write-back caching, eviction policies, distributed caching and more!
To read more on Caching, check out our blog on blog.coderco.io