October 2018
Intermediate to advanced
332 pages
8h 9m
English
Some routes, such as our home and post routes, take the parameters through the URL and return content specific to those parameters. We run into a problem if routes like these are cached, as the first rendering of the route will be returned for all requests, regardless of the URL parameters. The solution to this is rather simple. The key_prefix keyword argument in the cache method can be either a string or a function, which will be executed to dynamically generate a key.
This means that a function can be created to create, in turn, a key that is tied to the URL parameters, so that each request only returns a cached page if that specific combination of parameters was called before. In the blog/controllers.py ...