summaryrefslogtreecommitdiff
path: root/pylru.py
diff options
context:
space:
mode:
authorJuan Batiz-Benet <jbenet@cs.stanford.edu>2011-07-10 05:52:52 -0700
committerJuan Batiz-Benet <jbenet@cs.stanford.edu>2011-07-10 05:56:02 -0700
commit9525ec85063786716ab61a57dd69f556586792d3 (patch)
tree65d71ac288b6326e5d406b11fe0c3b527756049b /pylru.py
parenta96e83d7fb11c86349218eb2c22200d639665929 (diff)
downloadpylru-9525ec85063786716ab61a57dd69f556586792d3.tar.gz
Added keys, values, and items to allow iteration
Diffstat (limited to 'pylru.py')
-rw-r--r--pylru.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/pylru.py b/pylru.py
index 8015f37..55e4b67 100644
--- a/pylru.py
+++ b/pylru.py
@@ -178,7 +178,23 @@ class lrucache(object):
self.mtf(node)
self.head = node.next
+ def items(self):
+ # return the (key, value) pairs (from most recent to least)
+ # without modifying the cache order
+ return zip(self.keys(), self.values())
+
+ def keys(self):
+
+ # return the keys (from most recent to least) in the cache
+ # does not modify the cache order
+ return self.table.keys()
+
+ def values(self):
+
+ # return the values in the cache (from most recent to least)
+ # does not modify the cache order
+ return [node.obj for node in self.table.values()]
def size(self, size=None):
@@ -324,7 +340,6 @@ class lruwrap(object):
except KeyError:
pass
-
def sync(self):
if self.writeback:
for key in self.dirty: