From d434fa3017a2889650d58b449314090fce970e3c Mon Sep 17 00:00:00 2001
From: Carsten Hinz <c.hinz@fz-juelich.de>
Date: Wed, 8 May 2024 14:01:05 +0200
Subject: [PATCH] added a second cahce to preserve deleted entries.

---
 toargridding/toar_rest_client.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/toargridding/toar_rest_client.py b/toargridding/toar_rest_client.py
index 7fdc820..cfa30d7 100644
--- a/toargridding/toar_rest_client.py
+++ b/toargridding/toar_rest_client.py
@@ -99,7 +99,7 @@ class Cache:
     
     """
 
-    def __init__(self, cache_dir : Path):
+    def __init__(self, cache_dir : Path, fn = "status_endpoints" ):
         """constructor
         
         Throws exception if cache directory does not exists.
@@ -111,7 +111,7 @@ class Cache:
         
         if not cache_dir.exists():
             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
             with open(self.cache_file, "w") as cache:
@@ -171,6 +171,7 @@ class Connection:
 
         self.endpoint = endpoint
         self.cache = Cache(cache_dir)
+        self.cache_backup = Cache(cache_dir, "status_endpoints.old")
         # max wait time is 30min
         self.wait_seconds = [minutes * 60 for minutes in (5, 5, 5, 5, 5, 5)]
 
@@ -217,7 +218,8 @@ class Connection:
                 print("Reason: {e.response.reason}")
                 print("Text: {e.response.text}")
                 #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:
                 raise RuntimeError(f"An error occurred during accessing a cached request")
             else:
-- 
GitLab