Django - variable based django template cache expires

Cannot invalidate specific template cache in django

def invalidate_cache_key(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)

However, I have a situation where I need to delete all cached fragments for which a particular variable was passed. For example, delete all cached fragments about the Toyota car brand.

{% cache 100000 car_content car.brand %}

Essentially, is there a way to get all cache keys based on a specific set of criteria? I thought about changing the source of the cache, but I was wondering if there could be a better solution to this problem.

+5
source share
2 answers

I do this with namespace caching. Here is a worthy explanation:

http://blog.dberg.org/2008/07/user-based-memcached-namespaces.html

+1

:

{% cache 100000 car_content car.brand car.brand.last_modified %}

, , .

0

All Articles