summaryrefslogtreecommitdiff
path: root/pylru.py
diff options
context:
space:
mode:
Diffstat (limited to 'pylru.py')
-rw-r--r--pylru.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/pylru.py b/pylru.py
index eef0593..e69cadb 100644
--- a/pylru.py
+++ b/pylru.py
@@ -535,8 +535,22 @@ import functools
class lrudecorator(object):
def __init__(self, size):
- self.size = size
+ self.cache = lrucache(size)
def __call__(self, func):
- wrapper = FunctionCacheManager(func, self.size)
+ def wrapper(*args, **kwargs):
+ kwtuple = tuple((key, kwargs[key]) for key in sorted(kwargs.keys()))
+ key = (args, kwtuple)
+ try:
+ return self.cache[key]
+ except KeyError:
+ pass
+
+ value = func(*args, **kwargs)
+ self.cache[key] = value
+ return value
+
+ wrapper.cache = self.cache
+ wrapper.size = self.cache.size
+ wrapper.clear = self.cache.clear
return functools.update_wrapper(wrapper, func)