summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Hutchinson <jlhutch@gmail.com>2018-05-05 21:45:09 -0500
committerJay Hutchinson <jlhutch@gmail.com>2018-05-06 11:12:21 -0500
commite09228909ef01df7bd6e94a7a66232be60ff85ee (patch)
tree16868d8eba552fa860ef1f349e7ffc1ad0327d6d
parent79401370c122720155cde0f4fa600698d5413541 (diff)
downloadpylru-e09228909ef01df7bd6e94a7a66232be60ff85ee.tar.gz
Simplified logic of a couple __getitem__ implementations.
-rw-r--r--pylru.py16
1 files changed, 4 insertions, 12 deletions
diff --git a/pylru.py b/pylru.py
index 9ca120d..0a9bf11 100644
--- a/pylru.py
+++ b/pylru.py
@@ -299,13 +299,9 @@ class WriteThroughCacheManager(object):
return False
def __getitem__(self, key):
- # First we try the cache. If successful we just return the value. If
- # not we catch KeyError and ignore it since that just means the key
- # was not in the cache.
- try:
+ # Try the cache first. If successful we can just return the value.
+ if key in self.cache:
return self.cache[key]
- except KeyError:
- pass
# It wasn't in the cache. Look it up in the store, add the entry to
# the cache, and return the value.
@@ -391,13 +387,9 @@ class WriteBackCacheManager(object):
return False
def __getitem__(self, key):
- # First we try the cache. If successful we just return the value. If
- # not we catch KeyError and ignore it since that just means the key
- # was not in the cache.
- try:
+ # Try the cache first. If successful we can just return the value.
+ if key in self.cache:
return self.cache[key]
- except KeyError:
- pass
# It wasn't in the cache. Look it up in the store, add the entry to
# the cache, and return the value.