about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--wqflask/base/data_set.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py
index 8188d90c..51244303 100644
--- a/wqflask/base/data_set.py
+++ b/wqflask/base/data_set.py
@@ -1243,7 +1243,7 @@ def geno_mrna_confidentiality(ob):
         return True
 
 
-def check_if_dataset_modified(dataset_name, cached_timestamp):
+def check_if_dataset_modified(dataset_name: str, cached_timestamp):
     """function to check if the dataset has been modified"""
     last_modified = "query results"
     return (cached_timestamp == last_modified_timestamp)
@@ -1264,4 +1264,18 @@ def cache_dataset_results(dataset_name: str, query_results: List):
     query_results = [list(results) for result in query_results]
 
     with open(file_path, "w") as file_handler:
-        json.dump(query_results, file_handler)
\ No newline at end of file
+        json.dump(query_results, file_handler)
+
+def fetch_cached_results(dataset_name: str):
+    """function to fetch the cached results"""
+    file_path = os.path.join(TMPDIR, f"{dataset_name}.json")
+
+    try:
+        with open(file_path) as file_handler:
+            data = json.load(file_handler)
+            # check if table has been modified
+            if check_if_dataset_modified(dataset_name["timestamp"]):
+                return data[dataset_name]
+    except FileNotFoundError:
+        # take actions continue to fetch dataset results and fetch results
+        pass
\ No newline at end of file