summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lru.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/lru.py b/lru.py
index 7b2fd99..ec257c3 100644
--- a/lru.py
+++ b/lru.py
@@ -289,3 +289,20 @@ class lruwrap(object):
except KeyError:
pass
del self.store[key]
+
+
+class lrudecorator(object):
+ def __init__(self, func, size):
+ self.func = func
+ self.cache = lrucache(size)
+
+ def __call__(self, *args, **kwargs):
+ try:
+ value = self.cache[(args, kwargs)]
+ except KeyError:
+ pass
+
+ value = self.func(*args, **kwargs)
+ self.cache[(args, kwargs)] = value
+ return value
+