zhanhailiang 日期:2014-12-12
Requirements Background
Typically, the cache logic is to set an expiration time, and if the cache fails, the request backend reads the data and updates the cache. However, this scenario can be problematic in high-QPS scenarios where all requests are fully propagated to the backend during the time period when the cache fails, the request backend reads, and the cache is updated, and the scenario has a large number of requests to the backend. So our goal is to reduce this part of the request.
Implementation Scenarios
The code is as follows: https://github.com/billfeller/blog.csdn.net-billfeller/blob/master/cache.php
Programme evaluation
- From the end result, the lock-based implementation mechanism minimizes back-end requests. Taking factor=10 as an example, the probability-based implementation mechanism can reduce the number of requests by 90%, but the lock-based implementation mechanism guarantees that only one back-end request can be made in any scenario.
- From the implementation perspective, the lock-based implementation mechanism requires additional memcached operations, with the worst case requiring 3 additional memcached operations;
Cache policy Optimization