Bugfix for caching between sessions
This commit is contained in:
parent
eca1db8622
commit
e9bef6db68
|
@ -422,8 +422,8 @@ class _Network:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not file_path:
|
if not file_path:
|
||||||
file_descriptor, file_path = tempfile.mkstemp(prefix="pylast_tmp_")
|
self.cache_backend = _ShelfCacheBackend.create_shelf()
|
||||||
os.close(file_descriptor)
|
return
|
||||||
|
|
||||||
self.cache_backend = _ShelfCacheBackend(file_path)
|
self.cache_backend = _ShelfCacheBackend(file_path)
|
||||||
|
|
||||||
|
@ -784,8 +784,11 @@ class LibreFMNetwork(_Network):
|
||||||
class _ShelfCacheBackend:
|
class _ShelfCacheBackend:
|
||||||
"""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, flag=None):
|
||||||
self.shelf = shelve.open(file_path, flag="n")
|
if flag:
|
||||||
|
self.shelf = shelve.open(file_path, flag=flag)
|
||||||
|
else:
|
||||||
|
self.shelf = shelve.open(file_path)
|
||||||
self.cache_keys = set(self.shelf.keys())
|
self.cache_keys = set(self.shelf.keys())
|
||||||
|
|
||||||
def __contains__(self, key):
|
def __contains__(self, key):
|
||||||
|
@ -801,6 +804,12 @@ class _ShelfCacheBackend:
|
||||||
self.cache_keys.add(key)
|
self.cache_keys.add(key)
|
||||||
self.shelf[key] = xml_string
|
self.shelf[key] = xml_string
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create_shelf(cls):
|
||||||
|
file_descriptor, file_path = tempfile.mkstemp(prefix="pylast_tmp_")
|
||||||
|
os.close(file_descriptor)
|
||||||
|
return cls(file_path=file_path, flag="n")
|
||||||
|
|
||||||
|
|
||||||
class _Request:
|
class _Request:
|
||||||
"""Representing an abstract web service operation."""
|
"""Representing an abstract web service operation."""
|
||||||
|
|
Loading…
Reference in a new issue