Created
December 15, 2015 08:32
-
-
Save apua/5312a19fa336b16bac7c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import functools | |
| # decorator for method?! | |
| class Cache(object): | |
| def __init__(self, func): | |
| self.func = func | |
| self.cache = {} | |
| def __call__(self, *args): | |
| if args not in self.cache: | |
| self.cache[args] = self.func(*args) | |
| return self.cache[args] | |
| def __repr__(self): | |
| return self.func.__doc__ | |
| def __get__(self, obj, objtype): | |
| return functools.partial(self.__call__, obj) | |
| cache = Cache | |
| class C(object): | |
| @cache | |
| def main(self): | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment