July 2019
Beginner to intermediate
302 pages
9h 38m
English
Many of us might think that such caching will fail in the case of a single category or product page, where each record has a separate page. The solution to this is memoization. It is similar to caching, with the difference being that it stores the result of a method in the cache, along with the information on the parameters that were passed. So, when a method is created with the same parameters multiple times, the result is loaded from the cache rather than making a database hit. Implementing memoization is quite simple:
@catalog.route('/product/<id>')
@cache.memoize(120)
def product(id):
# Fetch and display the product
Now, if we call a URL, say, http://127.0.0.1:5000/product/1, in our browser for the first time, it will ...