Merge pull request #244 from pylast/fix-cache-key-lookup-performance

Fix serious cache key lookup performance problem
This commit is contained in:
Hugo 2018-01-11 12:27:52 +02:00 committed by GitHub
commit 423db55bd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -713,6 +713,10 @@ class _ShelfCacheBackend(object):
"""Used as a backend for caching cacheable requests.""" """Used as a backend for caching cacheable requests."""
def __init__(self, file_path=None): def __init__(self, file_path=None):
self.shelf = shelve.open(file_path) self.shelf = shelve.open(file_path)
self.cache_keys = set(self.shelf.keys())
def __contains__(self, key):
return key in self.cache_keys
def __iter__(self): def __iter__(self):
return iter(self.shelf.keys()) return iter(self.shelf.keys())
@ -721,6 +725,7 @@ class _ShelfCacheBackend(object):
return self.shelf[key] return self.shelf[key]
def set_xml(self, key, xml_string): def set_xml(self, key, xml_string):
self.cache_keys.add(key)
self.shelf[key] = xml_string self.shelf[key] = xml_string