From e09228909ef01df7bd6e94a7a66232be60ff85ee Mon Sep 17 00:00:00 2001 From: Jay Hutchinson Date: Sat, 5 May 2018 21:45:09 -0500 Subject: Simplified logic of a couple __getitem__ implementations. --- pylru.py | 16 ++++------------ 1 file 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. -- cgit v1.2.1