Django cache stores different key on get params

1k Views Asked by At

I am using django cache with django-redis-cache as a backend.

with:

@cache_page(60*60*24)

decorator on views.

Now the issue I am facing is every get request is being stored with a different key in redis. I have to display the same page for any get parameters. Is there any way to force cache to ignore get parameters while serving and making the key.

1

There are 1 best solutions below

1
On

There's of course "a way" to compute a same cache key whatever the request's querystring, but it requires a bit of work - you'll have to rewrite your own cache_page implementation based on the low-level cache API (which is documented here https://docs.djangoproject.com/en/1.6/topics/cache/#the-low-level-cache-api). You may also read the source code for the CacheMiddleware (upon which cache_page is built).

Now I have to say I don't get the point of ignoring the querystring when generating the cache key for a page cache.