Simplify the caching of service keys to hopefully avoid the not found issue

Makes accesses simpler and reduces the number of dictionaries to one, in an effort to remove race conditions
This commit is contained in:
Joseph Schorr 2017-05-26 13:49:50 -04:00
parent a51afaaecf
commit 0ba54ed4fc
2 changed files with 28 additions and 28 deletions

View file

@ -38,18 +38,20 @@ class ExpiresDict(object):
return found.value
# Otherwise the key has expired or was not found. Rebuild the cache and check it again.
self._rebuild()
found = self._items.get(key)
if found is None:
items = self._rebuild()
found_item = items.get(key)
if found_item is None:
return default_value
return found.value
return found_item.value
def __contains__(self, key):
return self.get(key) is not None
def _rebuild(self):
self._items = self._rebuilder()
items = self._rebuilder()
self._items = items
return items
def set(self, key, value, expires=None):
self._items[key] = ExpiresEntry(value, expires=expires)