Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear cache when used with @property #4

Open
j-walker23 opened this issue Sep 29, 2016 · 2 comments
Open

Clear cache when used with @property #4

j-walker23 opened this issue Sep 29, 2016 · 2 comments

Comments

@j-walker23
Copy link

This lib is cool, thank you.

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

@vaab
Copy link
Member

vaab commented Oct 4, 2016

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.

@j-walker23
Copy link
Author

You are the man. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants