django-templatesdjango-cache

Django template reading wrong cache value


I am caching in my django template like this.

{% load cache %}
{% cache cache_timeout key_name model_id %}
    <div>          
       {{some_variable}}
    </div>
{% endcache %}

Where cache_timeout is a variable I set in the view with the timeout.

I am also manually changing the cache value using the snippet on the accepted answer to this question

It is working fine as I know the template sets the value with the same key I use. The thing is that when I update the cache (I am checking the updated value and it is the one I set) the template keeps showing the previous value for some time(way smaller than the timeout) before updating.

I need the template to update the value read immediately.


Solution

  • Check the HTTP headers that are coming back with the response. Sounds like browser caching.