Skip to content
Snippets Groups Projects
Commit d434fa30 authored by Carsten Hinz's avatar Carsten Hinz
Browse files

added a second cahce to preserve deleted entries.

parent 28004e86
No related branches found
No related tags found
1 merge request!11Creation of first beta release version
...@@ -99,7 +99,7 @@ class Cache: ...@@ -99,7 +99,7 @@ class Cache:
""" """
def __init__(self, cache_dir : Path): def __init__(self, cache_dir : Path, fn = "status_endpoints" ):
"""constructor """constructor
Throws exception if cache directory does not exists. Throws exception if cache directory does not exists.
...@@ -111,7 +111,7 @@ class Cache: ...@@ -111,7 +111,7 @@ class Cache:
if not cache_dir.exists(): if not cache_dir.exists():
raise RuntimeError(f"Given directory for saving cache file does not exists. Path: {cache_dir}") raise RuntimeError(f"Given directory for saving cache file does not exists. Path: {cache_dir}")
self.cache_file = cache_dir / "status_endpoints.json" self.cache_file = cache_dir / fn / ".json"
if not self.cache_file.is_file(): # initialize cache with dummy values if not self.cache_file.is_file(): # initialize cache with dummy values
with open(self.cache_file, "w") as cache: with open(self.cache_file, "w") as cache:
...@@ -171,6 +171,7 @@ class Connection: ...@@ -171,6 +171,7 @@ class Connection:
self.endpoint = endpoint self.endpoint = endpoint
self.cache = Cache(cache_dir) self.cache = Cache(cache_dir)
self.cache_backup = Cache(cache_dir, "status_endpoints.old")
# max wait time is 30min # max wait time is 30min
self.wait_seconds = [minutes * 60 for minutes in (5, 5, 5, 5, 5, 5)] self.wait_seconds = [minutes * 60 for minutes in (5, 5, 5, 5, 5, 5)]
...@@ -217,7 +218,8 @@ class Connection: ...@@ -217,7 +218,8 @@ class Connection:
print("Reason: {e.response.reason}") print("Reason: {e.response.reason}")
print("Text: {e.response.text}") print("Text: {e.response.text}")
#will be overwritten in the next step... #will be overwritten in the next step...
#self.cache.remove(query_options.cache_key) self.cache_backup.put(query_options.cache_key, status_endpoint)
self.cache.remove(query_options.cache_key)
except: except:
raise RuntimeError(f"An error occurred during accessing a cached request") raise RuntimeError(f"An error occurred during accessing a cached request")
else: else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment