Simple processing K-> V cache invalidation after the high concurrent access t

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Daily programming, for some concurrency or data the higher amount of database operations, we will add a layer of buffer layer on the front end, and set the time to failure, it is usually mongoDB or memcached, the simple procedure is as follows:



This model is not in the concurrency value is too high or the data operation efficiency under the condition of high basic no problem.
But perhaps you have seen, If (cache invalidation & & just met with a high amount of & & database operation for a long time) then?
  1 cache invalidation
  2 the first process to the database to obtain new data, If SQL+ program logic time 5S
  the 5S 3, Second, third... N are the only access to the invalid cache, So they are connected to the database...
  4 the results obviously;, Database lock table -> database accumulated lots of processes -> until the database failed!

So, How to solve this problem? In fact, the simplest solution is:
Add a tag, Similar to the file lock, This program is used to determine the update cache.
If, Directly returns the old cache (marked with a set time to failure, Avoid due to program errors lead to mark not delete the cache does not update problem)
If not, It sets a flag, Then data acquisition and cache update, Finally, the delete marker.

PS. first generation cache may be some users cannot see the data, But the probability is very small, And through other ways such as manual generation of such to solve.


The process is as follows



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Sebastian at October 23, 2013 - 9:04 PM