diff options
author | Jay Hutchinson <jlhutch@gmail.com> | 2018-05-05 21:45:09 -0500 |
---|---|---|
committer | Jay Hutchinson <jlhutch@gmail.com> | 2018-05-06 11:12:21 -0500 |
commit | e09228909ef01df7bd6e94a7a66232be60ff85ee (patch) | |
tree | 16868d8eba552fa860ef1f349e7ffc1ad0327d6d | |
parent | 79401370c122720155cde0f4fa600698d5413541 (diff) | |
download | pylru-e09228909ef01df7bd6e94a7a66232be60ff85ee.tar.gz |
Simplified logic of a couple __getitem__ implementations.
-rw-r--r-- | pylru.py | 16 |
1 files changed, 4 insertions, 12 deletions
@@ -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. |