summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjlhutch <jlhutch@gmail.com>2014-04-18 12:12:45 -0500
committerjlhutch <jlhutch@gmail.com>2014-04-18 12:12:45 -0500
commit387dcfbc5de88f7f9a0b961f0330ccd847628a42 (patch)
treea9a050618e74e4cb42ebd307f4ecb5e7b78ea764
parent2f9d1f8b33809a32aa510304b6c3da41461f2f41 (diff)
parent4570b749eb05152512a6dcdc2e88715d9902cb87 (diff)
downloadpylru-387dcfbc5de88f7f9a0b961f0330ccd847628a42.tar.gz
Merge pull request #6 from dobesv/patch-1
Add "get" method to match dict API.
-rw-r--r--pylru.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/pylru.py b/pylru.py
index 3de5cb0..13aba67 100644
--- a/pylru.py
+++ b/pylru.py
@@ -1,5 +1,4 @@
-
# Cache implementaion with a Least Recently Used (LRU) replacement policy and
# a basic dictionary interface.
@@ -100,6 +99,10 @@ class lrucache(object):
# Return the value.
return node.value
+ def get(self, key, default=None):
+ """Get an item - return default (None) if not present"""
+ try: return self[key]
+ except KeyError: return default
def __setitem__(self, key, value):
# First, see if any value is stored under 'key' in the cache already.