Nginx/Django caching site even when caching explicitly disabled

前端 未结 2 1327
时光取名叫无心
时光取名叫无心 2021-01-26 03:30

I am working on a development site built in Django in a virtualenv on an Nginx server using uwsgi.

In

相关标签:
2条回答
  • 2021-01-26 04:01

    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})

    0 讨论(0)
  • 2021-01-26 04:06

    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:

    from django.views.decorators.cache import never_cache
    
    class MyView(View):
    
        @never_cache
        def dispatch(self,request,*args,**kwargs):
            return super().dispatch(request,*args,**kwargs)
    

    or, in a function based view:

    @never_cache
    def myview(request, ...):
       ...
    

    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:

    • /etc/nginx/nginx.conf
    • /etc/nginx/sites-available/*.conf

    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:

    ...
    html {
        ...
        sendfile off;
        ...
    
    0 讨论(0)
提交回复
热议问题