Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7589609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:12:15+00:00 2026-05-30T20:12:15+00:00

I have cache tag in the base template: {% cache 100000 categories %} Categories

  • 0

I have cache tag in the base template:

{% cache 100000 categories %}
    Categories output
{% endcache %}

When I add new category through Django admin, I want invalidate this cache:

class CategoriesAdmin(admin.ModelAdmin):
    def save_model(self, request, obj, form, change):
        super(CategoriesAdmin, self).save_model(request, obj, form, change)

        cache.delete('categories')

But the cache is stay valid! What is wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:12:16+00:00Added an answer on May 30, 2026 at 8:12 pm

    That’s because the actual key is not “categories”, but rather one that’s dynamically constructed by Django using the following:

    args = md5_constructor(u':'.join([urlquote(resolve_variable(var, context)) for var in self.vary_on]))
    cache_key = 'template.cache.%s.%s' % (self.fragment_name, args.hexdigest())
    

    See: https://code.djangoproject.com/browser/django/tags/releases/1.3.1/django/templatetags/cache.py

    In general, the key is going to be in the format: template.cache.categories.[hexdigest]. So the tricky part is figuring out the hexdigest part.

    I found the following Django snippet (in the comments), which looks like it should still work (from 2009):

    from django.core.cache import cache
    from django.utils.hashcompat import md5_constructor
    from django.utils.http import urlquote
    
    def invalidate_template_cache(fragment_name, *variables):
        args = md5_constructor(u':'.join([urlquote(var) for var in variables]))
        cache_key = 'template.cache.%s.%s' % (fragment_name, args.hexdigest())
        cache.delete(cache_key)
    

    Since you’re not passing any variables to vary on to the templatetag, you can call that with just: invalidate_template_cache('categories'). Otherwise, you’d need to pass in a list of all the variables the template tag varies on as the second argument.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have model with tag context: class Product < ActiveRecord::Base acts_as_taggable_on :categories end I'm
I have seen the wiki page on how to cache block output on Magentocommerce.com
I have a Category model which uses acts_as_tree class Category < ActiveRecord::Base acts_as_tree :order=>name
I have a cache which has soft references to the cached objects. I am
we have a cache which I would like to put some transaction scopes around
I am using NHibernate and have a cache region specified in my NHibernate configuration:
I just started using SVN, and I have a cache directory that I don't
During development I have to clear cache in Firefox all the time in order
I have a web server which saves cache files and keeps them for 7
I have a Perl script where I maintain a very simple cache using a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.