Making the cache mechanism asynchronous
In Chapter 3, Configuring the Swoole Application Server, we explored the Octane::tick()
method.
The tick()
method allows you to execute a function every n seconds.
The caching strategy could be reviewed by delegating data loading to a specific function. This specific function is responsible for retrieving data with the query from the database (and not from the cache), and once the data is retrieved, the function stores the results in the cache. The function is called via the Octane::tick()
method and executed – for example, maybe every 60 seconds, fresh data from the database is retrieved, and it fills the cache. All the requests retrieve the data from the cache.
With the asynchronous caching strategy, all the requests retrieve data from the cache.
The cache is refreshed by the task called via tick()
.
To implement the asynchronous caching strategy, we are doing the following:
- Implementing the
tick()
function in the...