Discover more from CoderCo
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".
Thanks for reading CoderCo! Subscribe for free to receive new posts and support my work.
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