Sometimes we create property within our model for utility helper. And django provide decorator “@cached_property” for caching heavy computation within our property.
class Member(models.Model): # field definitions. @cached_property def score(self): return # heavy computation/query
I got a problem once testing my model and the property is still load the cached version of data instead of the latest. Here is how to invalidate cached property.
del member.score # Invalidate cache. delattr(member, 'score') # Alternative to invalidate cache.