Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Caching - Remove caching for certain pages

I would like to turn caching off for certain pages when that view is accessed. It's for a page that simply queries model objects.

it seems like when 'django.middleware.cache.FetchFromCacheMiddleware', is enabled, it requires another "refresh" from the browser to see the latest data.

Is there any way to prevent this?

Thank you.

like image 219
DavidL Avatar asked Dec 28 '22 07:12

DavidL


1 Answers

https://docs.djangoproject.com/en/dev/topics/cache/#controlling-cache-using-other-headers

If you want to use headers to disable caching altogether, django.views.decorators.cache.never_cache is a view decorator that adds headers to ensure the response won't be cached by browsers or other caches. Example:

from django.views.decorators.cache import never_cache

@never_cache
def myview(request):
     # ...
like image 96
Yuji 'Tomita' Tomita Avatar answered Jan 08 '23 03:01

Yuji 'Tomita' Tomita