As far as I am concerned, PHP uses Memache or Redis cache data, when the data has updated data, according to the label to clear out the data, then there is a set of automatic update strategy?
Reply content:
As far as I am concerned, PHP uses Memache or Redis cache data, when the data has updated data, according to the label to clear out the data, then there is a set of automatic update strategy?
Delete is better than update, if your request contains more than one data update, which will trigger multiple cache updates, but in fact only the last updated cache is valid. If the execution cost of the update cache is high, it may cause an issue of execution efficiency under occasional high-frequency updates.
In contrast, the cost of deleting a cache is lower, and no new cache is generated without a request, and no data is wasted in the middle of the update.
This removal strategy is probably not suitable for high-load sites, and for this type of application, preferring to sacrifice consistency does not allow a large number of requests to penetrate the database directly, but for most Web sites this should not be a problem.
This is similar to the problem I solved a few days ago, sell a Moe!
In fact, this kind of problem, I personally think that belongs to the framework problem, or the larger point is that the architectural problem is not too ~ so if just staring at the business to think about this problem, may be very powerless ~
The reason I finally took the "crawler" solution was that it was not realized at the beginning of the development that the cache has become the standard of the present website, is non-functional but necessary requirements!
The data to be updated into the queue, open process to run the queue, in the process of processing, can you?
The general way is to do processing at the model level, because the data additions and deletions are carried out at the model level. There are many PHP frameworks that support event binding, so you can also use event mechanisms to handle them.
It's not hard to do it uniformly in model.
= = always do the cache does not update the data, the first encounter, think about it, you can do in the database such as MySQL trigger.
Rookie Pat.
Write the update's Post Method _after_update () in the model and delete the cache in the Post method
For the landlord's question, I have also carefully thought. Essentially, a condition is added when the cache is read. IF (Cache invalidation) then (rebuild) ELSE (returns cached data). Such a mechanism is really tempting for development, so don't worry about updating the data to forget about the cache. But... Where does the data that determines the cache invalidation in the IF condition come from? I want either the database, either the cache, or the queue. So the individual feels that the cost of achieving such an automatic function is a bit high.
PHP's YII framework has a cache-dependent module that can be seen, in general thinking as described above. The "cache dependency" is equivalent to the above-mentioned condition of "cache invalidation"; in Yii, there are many kinds of cache dependencies, such as database, cache, file update time, etc.