Login

Delete template fragment cache

Author:
DeRomanok
Posted:
March 24, 2012
Language:
Python
Version:
1.3
Score:
0 (after 0 ratings)

Template:

{% load cache %} {% cache 1800 posts blog.pk %} {# Show posts #} {% endcache %}

Code:

def view(request, pk): # Code blog = get_object_or_404(Blog, pk=pk) delete_template_fragment_cache('posts', blog.pk) # Code

1
2
3
4
5
import hashlib
from django.core.cache import cache

def delete_template_fragment_cache(fragment_name='', *args):
    cache.delete('template.cache.%s.%s' % (fragment_name, hashlib.md5(u':'.join([arg for arg in args])).hexdigest()))

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 3 months, 1 week ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 3 months, 2 weeks ago
  3. Serializer factory with Django Rest Framework by julio 10 months, 1 week ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 11 months ago
  5. Help text hyperlinks by sa2812 11 months, 3 weeks ago

Comments

Please login first before commenting.