Currently, php uses memache or redis to cache data. when data is updated and data is cleared Based on tags, is there a set of automatic update policies? Currently, php uses memache or redis to cache data. when data is updated and data is cleared Based on tags, is there a set of automatic update policies?
Reply content:
Currently, php uses memache or redis to cache data. when data is updated and data is cleared Based on tags, is there a set of automatic update policies?
Deletion is better than update. If your request contains multiple data updates, this will trigger multiple cache updates, but in fact only the last update cache is valid. If the execution cost of the update cache is high, the execution efficiency may be caused by occasional frequent updates.
The cost of deleting the cache is relatively lower, and no new cache will be generated without a request, and data update in the middle will not be wasted.
This deletion policy may not be applicable to high-load websites. For such applications, you would rather sacrifice consistency than directly penetrating a large number of requests to the database. However, for most websites, this approach should not be a problem.
This is similar to the problem I solved a few days ago!
In fact, I personally think this type of problem is a framework issue, or if it is bigger, it is not an architecture issue ~ So if you just stare at the business to think about this problem, it may be very weak ~
The reason why I finally adopted the "crawler" solution is that I didn't realize that cache has become a standard for today's websites at the beginning of development. It is non-functional but necessary!
Add the data to be updated to the queue, start the process to run the queue, and process the data in the process. Can this problem be solved?
The general method is to process data at the model layer, because data addition, deletion, and modification are performed at the model layer. Many php frameworks support event binding, so they can also be processed using the event mechanism.
If the Model is processed in a unified manner, this is not difficult.
=. = Data is always cached but not updated. The first time I encountered it, I thought about it, I could make a trigger in a database such as MYSQL.
Cainiao pat.
Write the POST method _ after_update () of update in the Model and delete the cache in the POST method.
I have also carefully considered questions about the landlord. In essence, a condition is added during cache reading. IF (cache failure) THEN (Reconstruction) ELSE (return cache data ). This mechanism is really attractive for development, so you don't have to worry about updating data and forgetting to clear the cache. But... Where does the data in the IF condition determine that the cache is invalid? I want to either database, cache, or queue. Therefore, I personally think it is a little expensive to implement such an automatic function.
The YII framework of PHP has a cache-dependent module. The general idea is described above. The "cache dependency" is equivalent to the condition described above for determining "cache invalidation". In YII, there are many cache dependencies, such as databases, caches, and file update times.