kids.cache
kids.cache copied to clipboard
Clear cache when used with @property
This lib is cool, thank you.
Question about @cache with @property. Is it possible to clear the cache?
Yes, but it might not consider this to be trivial, here follows 2 different way:
Say MyObject class defines the cached property foo, then you can access the cached function:
MyObject.foo.fget, so for instance:MyObject.foo.fget.cache_clear().- or by using
undecorate(..)provided inkids.cache.
from kids.cache import undecorate
undecorate(MyObject.foo)[1].cache_clear()
Please note that the second method will work with ANY cached property (namely cached method, property, classmethod, staticmethod, class).
I'd like to keep this thread open as a reminder to answer your question in the README, and probably implement a little helper on this topic.
You are the man. Thank you!