from django.core.cache import cache def stales_cache(cache_key): def paramed_decorator(func): def decorated(self, *args, **kw): key = cache_key % self.__dict__ cache.delete(key) return func(self, *args, **kw) decorated.__doc__ = func.__doc__ decorated.__dict__ = func.__dict__ return decorated return paramed_decorator # usage class SomeClass(models.Model): # fields name = CharField(...) @stales_cache("SomeClass_some_key_that_depends_on_name_%(name)") @stales_cache("SomeClass_some_other_key_that_depends_on_name_%(name)") def update_name(self, new_name): self.name = new_name self.save()