Its not to hard to invalidate a particular 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 that have had a certain variable passed to them. For example, delete all cached fragments about the car brand 'Toyota'.
{% cache 100000 car_content car.brand %}
Essentially is there a way to get all cache_keys based on a certain set of criteria? I have thought dangerously about changing the cache source but I was wondering if there might be a better solution to this problem.
I do this with caching namespaces. Here is a decent explanation:
http://blog.dberg.org/2008/07/user-based-memcached-namespaces.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With