Types of Caching
- Spatial Cache
It works on keeping in cache all the pages which are present nearby of a particular request. If the application is able to predict what the next set of elements/tools is going to be used then it can bring that into memory.
Example – if the application is Photoshop – if the user uses the Crop tool, he is very likely to use the Rotate tool. So it’s better to get their functioning along in cache.
Another could be if one uses Black template in photo, the program should render thumbnails for all Darker templates too.
- Temporal Cache
It works on the most frequently used data. So most applications work on this kind of caching. We keep the MRU in cache as the user will surely use them.
Example – In a search engine, if a query is being used frequently so its results can be cached and so it will save a lot of re-computation.
- Distributed Cache – It’s just a distributed version of cache. It scales up well but is difficult to keep in sync with the data. Example – Reddis, Memcache
- Write Through Cache – The data to be read is from cache. If data is not available then it is written into cache and disk simultaneously and later the output is given. This ensures consistency and simplicity to implement. However, as we are doing two writes so latency is higher for the response.
- . Write Back Cache – The data to be read is from cache. If data is not available then it is written into cache and output is given, later it’s the responsibility of the cache to write to the disk. This ensures fast response but it’s complex to implement, as there can be many failures in case the cache fails and there will be inconsistent data.