Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I delete a cached template fragment in Django?

Previously, I had set up a cached chunk of HTML in my Django template as follows.

{% load cache %}            
    {% cache 10000 courseTable %} <!-- Cached HTML --> {% endcache %}

Now, I have updated this cached content and want to refresh it. I tried changing the time to no avail:

{% load cache %}            
    {% cache 0 courseTable %} <!-- Updated Cached HTML --> {% endcache %}

In this case, the page still displays the old cached HTML.

I also tried removing the template tags associated with caching and reinserting them. However, in this case, the content just reverts to the originally cached content after I reinsert the cache template tags.

What can I do? I do not want to wait about 2 hours to reload my cache.

like image 527
dangerChihuahua007 Avatar asked May 28 '12 03:05

dangerChihuahua007


1 Answers

If you could afford to empty memcached entirely, run flush_all cmd or simply

from django.core.cache import cache
cache.clear()

Or else you have to generate the cache-key manually. The timeout will not be refreshed until the key is expired.

like image 169
okm Avatar answered Sep 23 '22 17:09

okm