I am working on a development site built in Django in a virtualenv on an Nginx server using uwsgi.
In the uwsgi config file I have:
py-autoreload = 1
Most of the time caching is enabled in settings.py:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/www/example.com/cache',
}
}
but when I am working on the site, I replace the BACKEND and LOCATION lines above with:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
}
The problem I have is that Django or Nginx is caching the site even when I disable caching and empty the cache.
It is very strange -- I can actually delete the main application folder (not the project folder) and the site continues to work.
I ran into this while modifying templates and finding that my updates were not reflected in site content.
I have tried option-reloading in Safari, loading in Chrome, private/incognito windows etc.
The only thing that reliably works is to restart the server.
Does Django, Nginx, uwsgi or virtualenv have some secret caching system that I don't know about?
Must be either a client-side caching or Nginx caching ;)
(1) in the first case, the browser in not requesting an updated resource because it has been told that the previous resource is still valid;
To confirm this, try using Chrome in incognito and see what happens.
If this is the case, I would add the "never_cache" decorator to the Django views:
or, in a function based view:
Using the "never_cache" decorator, you instruct the browser not to cache the page, so whenever the user requires it, he's browser will in turn hit the server.
(2) if not, must be Nginx; check all nginx config files:
and comment out any parameter containing "cache", then restart the service.
I would also turn off "sendfile" as suggested here: https://jeremyfelt.com/2013/01/08/clear-nginx-cache-in-vagrant/
by adjusting file
/etc/nginx/nginx.conf
as follows:I think you must have to share upper part of your view for more clarification.
But you can try this:
return render(request, template, {'context':context})