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

Add possibility to use cacheutils's decorator on class methods #70

Closed
grundic opened this issue May 6, 2016 · 4 comments
Closed

Add possibility to use cacheutils's decorator on class methods #70

grundic opened this issue May 6, 2016 · 4 comments

Comments

@grundic
Copy link

grundic commented May 6, 2016

Hi, great module first of all!
Right now I have to use cachetools module, which provides cachedmethod decorator for using with class/instance methods.

Would it be possible to implement same for cached decorator so it would be possible to run something like:

class Example(object):
    def __init__(self):
        self._cache = LRU()

    @cached(operator.attrgetter('_cache'))
    def heavy_func(self):
        print('Called')
        return 100500

instance = Example()
for _ in range(20):
    instance.heavy_func()  # should print `Called` just once

Ideally I would prefer single decorator for generic functions and for class methods, but if it's not possible it could be implemented with two different ones.

@mahmoud
Copy link
Owner

mahmoud commented May 6, 2016

Thank you, and yes, totally! Let me review your pull request over on #69.

@mahmoud
Copy link
Owner

mahmoud commented May 17, 2016

This now exists, in the form of cachedmethod. Let me know how it works for you, @grundic!

@grundic
Copy link
Author

grundic commented May 17, 2016

@mahmoud, looks just awesome! Much cleaner interface and easy to use. Thank you very much!
Could you please tell when do you plane to release it on PyPI?

@mahmoud
Copy link
Owner

mahmoud commented May 17, 2016

Glad you approve! I plan on releasing as soon as #75 is merged, so hopefully this week :)

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