Minor refactoring

This commit is contained in:
Miroslav Stampar
2012-07-30 10:06:14 +02:00
parent 60ebb97915
commit 20a66567a3
3 changed files with 9 additions and 10 deletions

8
lib/core/decorators.py Normal file
View File

@@ -0,0 +1,8 @@
# Reference: http://code.activestate.com/recipes/325205-cache-decorator-in-python-24/
def cachedmethod(f, cache={}):
def _(*args, **kwargs):
key = (f, tuple(args), frozenset(kwargs.items()))
if key not in cache:
cache[key] = f(*args, **kwargs)
return cache[key]
return _