Flask-Caching is a Flask extension package that allows us easily implement caching functionality. You can imagine a
cache as a dictionary object that contains key-value pairs. The key here is used to specify the resource to
cache, whereas the value is used to store the actual data to be cached. Take the resource for retrieving all the recipes as an example. The flow contains the following stages:
- Request the get
- Use the key to search for the existing cache (Flask-Caching will be using
hashed_argsto be the key value, for example,
- If the recipes were previously cached, return the cached data.
- If no cache for these recipes exists, follow the standard flow to get the recipes from the database.
- Save the result (the recipe data) in the cache.
- Return the recipe data.
The process is better illustrated through the following figure: