The cache Avalanche Cache Avalanche is due to the original cache invalidation (expired) and the new cache is not in the period. All requests to query the database, and the database CPU and memory caused great pressure, serious will cause database downtime. Thus forming a series of chain reaction, causing the whole system collapse.
(1) In this case, the general concurrency is not particularly high time, the most used solution is lock queue.
[Java] View Plain copy public object getproductlistnew () { const int cachetime = 30; const string cacheKey = "Product_list"; const string lockKey = cachekey; var cacheValue = Cachehelper.get (CacheKey); if (cachevalue != null) { return cachevalue; } else { lock (lockkey) { cachevalue = cachehelper.get (CacheKey); if (cachevalue != null)   &Nbsp; { return cacheValue; } else { cachevalue = getproductlistfromdb (); //here is generally sql query data. cachehelper.add (cachekey, cachevalue, CacheTime); } } return cacheValue; } }
(2) Lock queue is only to alleviate the pressure of the database, and does not improve the system throughput. Assuming that the key is locked during the cache rebuild during high concurrency, this is the 1000 requests that are 999 blocks in a block. This also causes the user to wait for a timeout, which is a stopgap method.
Another solution is to add the appropriate cache tag for each cached data, record whether the cache is invalidated, and update the data cache if the cache flag is invalidated.
[Java] View Plain copy public object getproductlistnew () { const int cachetime = 30; const string cacheKey = "Product_list"; //cache tags. const string cachesign = cachekey + "_sign"; var sign = cachehelper.get (cachesign); //Get cache values var cacheValue = Cachehelper.get (CacheKey); if (sign != null) {             &NB