1. Why and when to use caching
Several optimizations have been made for the three-level classification request, but the throughput is not too ideal. At this time, we need to use the cache.
What scenarios need to use caching?
Basic process in read mode
Pseudo code and pay attention to setting the expiration time
Basic process in write mode
I won’t say much about this, it’s to update the cache at the same time as writing to the database.
2. Local cache and distributed cache
Local caching is suitable for stand-alone applications, such as map for local caching, which is
If it is distributed
Problems caused by distributed local cache
1) Cache is not shared
In this case, each service has a cache, but this cache is not shared. At a certain level, when it is scheduled to another device, the cache may not exist in its service, so it needs to be queried again.
(2) Cache consistency problem
After the cache on one device is updated, the cache on other devices may not have been updated, so when you get data from other devices, you may get data that has not been updated.
Distributed cache
All data is placed in middleware to share cached data, such as redis. If the capacity of middleware is not enough, it can be solved by clustering.