How it works...
After adding the preceding code, to check whether the cache works as expected, fetch the list of categories by pointing the browser to http://127.0.0.1:5000/categories. This will save a key-value pair for this URL in the cache. Now, create a new category quickly and navigate to the same category list page. You will notice that the newly added category is not listed. Wait for a couple of minutes and then reload the page. The newly added category will be shown now. This is because the first time the category list was cached, it expired after 2 minutes, that is, 120 seconds.
This might seem to be a fault with the application, but in the case of large applications, this becomes a boon where the hits to the database are reduced, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access