diff options
author | dobesv <dobesv@gmail.com> | 2014-04-17 14:16:32 -0700 |
---|---|---|
committer | dobesv <dobesv@gmail.com> | 2014-04-17 14:16:32 -0700 |
commit | 4570b749eb05152512a6dcdc2e88715d9902cb87 (patch) | |
tree | a9a050618e74e4cb42ebd307f4ecb5e7b78ea764 | |
parent | 2f9d1f8b33809a32aa510304b6c3da41461f2f41 (diff) | |
download | pylru-4570b749eb05152512a6dcdc2e88715d9902cb87.tar.gz |
Add "get" method to match dict API.
-rw-r--r-- | pylru.py | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -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. |