kids.cache icon indicating copy to clipboard operation
kids.cache copied to clipboard

Clear cache when used with @property

Open j-walker23 opened this issue 9 years ago • 2 comments

This lib is cool, thank you.

Question about @cache with @property. Is it possible to clear the cache?

j-walker23 avatar Sep 29 '16 17:09 j-walker23

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 in kids.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.

vaab avatar Oct 04 '16 16:10 vaab

You are the man. Thank you!

j-walker23 avatar Oct 15 '16 08:10 j-walker23