Using caching with your application
Caching becomes an important and integral part of any web application when scaling or increasing the response time of your application becomes a question. Caching is the first thing that is implemented in these cases. Flask, by itself, does not provide any caching support by default, but Werkzeug does. Werkzeug has some basic support to cache with multiple backends, such as Memcached and Redis. This caching support of Werkzeug is implemented by a package called Flask-Caching, which we will use in this recipe.
Getting ready
We will install a Flask extension called flask-caching
, which simplifies the process of caching a lot:
$ pip install flask-caching
We will use our catalog application for this purpose and implement caching for some methods.
How to do it…
Implementing basic caching is pretty easy. Go through the following steps to do so:
- First, initialize
Cache
to work with our application. This is done in the application...