Clearing cache_page


A few of our endpoints serve up a set of “constants” as configured in the DB (imagine a list of countries, cities). So to optimise speed, we cached them with the cache_page decorator.

We’d like any changes made to be reflected instantaneously. I’d like to clear the cache using signals. Is there any function to obtain the cache key based on the URL of a view?

There’s a function, get_cache_key, which is passed a request.

A full request - with headers - is needed to be able to support the Vary options. Just having the URL is not sufficient.

I have used this decorator before and it has performed the job

from django.views.decorators.cache import never_cache