Fix dict KeyError (#153)

pull/1067/head
Anton Hulikau 2018-04-26 04:22:26 +03:00 committed by Donne Martin
parent f05373af48
commit 7a4dbb1b2a
1 changed files with 2 additions and 2 deletions

View File

@ -34,7 +34,7 @@ class Cache(object):
Accessing a node updates its position to the front of the LRU list. Accessing a node updates its position to the front of the LRU list.
""" """
node = self.lookup[query] node = self.lookup.get(query)
if node is None: if node is None:
return None return None
self.linked_list.move_to_front(node) self.linked_list.move_to_front(node)
@ -47,7 +47,7 @@ class Cache(object):
If the entry is new and the cache is at capacity, removes the oldest entry If the entry is new and the cache is at capacity, removes the oldest entry
before the new entry is added. before the new entry is added.
""" """
node = self.lookup[query] node = self.lookup.get(query)
if node is not None: if node is not None:
# Key exists in cache, update the value # Key exists in cache, update the value
node.results = results node.results = results