From 2eecb319f2727ca44a00f49431416af197c3f637 Mon Sep 17 00:00:00 2001 From: Abrar Mesbah Date: Thu, 7 Dec 2023 13:40:41 -0500 Subject: [PATCH 01/13] add cacheing for lookups --- src/results_cache.py | 18 ++++++++++++++++++ src/service_aggregator.py | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/results_cache.py b/src/results_cache.py index 7f6ddf0..a0c9188 100644 --- a/src/results_cache.py +++ b/src/results_cache.py @@ -35,6 +35,24 @@ def set_result(self, input_id, predicate, qualifiers, source_input, caller, work key = self.get_query_key(input_id, predicate, qualifiers, source_input, caller, workflow) self.redis.set(key, gzip.compress(json.dumps(final_answer).encode())) + + def get_lookup_query_key(self, workflow, query_graph): + keydict = {'workflow': workflow, 'query_graph': query_graph} + return json.dumps(keydict, sort_keys=True) + + def get_lookup_result(self, workflow, query_graph): + key = self.get_query_key(workflow, query_graph) + result = self.redis.get(key) + if result is not None: + result = json.loads(gzip.decompress(result)) + return result + + + def set_lookup_result(self, workflow, query_graph, final_answer): + key = self.get_query_key(workflow, query_graph) + + self.redis.set(key, gzip.compress(json.dumps(final_answer).encode())) + def clear_cache(self): self.redis.flushdb() diff --git a/src/service_aggregator.py b/src/service_aggregator.py index 6439d92..f38f697 100644 --- a/src/service_aggregator.py +++ b/src/service_aggregator.py @@ -168,6 +168,7 @@ async def entry(message, guid, coalesce_type, caller) -> (dict, int): results_cache = ResultsCache() override_cache = (message.get("parameters") or {}).get("override_cache") override_cache = override_cache if type(override_cache) is bool else False + results = None if infer: # We're going to cache infer queries, and we need to do that even if we're overriding the cache # because we need these values to post to the cache at the end. @@ -182,6 +183,16 @@ async def entry(message, guid, coalesce_type, caller) -> (dict, int): return results, 200 else: logger.info(f"{guid}: Results cache miss") + else: + if not override_cache: + try: + query_graph = message["query_graph"] + except: + return f"No query graph", 422 + results = results_cache.get_lookup_result(workflow_def, query_graph) + if results is not None: + logger.info(f"{guid}: Returning results cache lookup") + return results, 200 workflow = [] @@ -199,6 +210,9 @@ async def entry(message, guid, coalesce_type, caller) -> (dict, int): if infer: results_cache.set_result(input_id, predicate, qualifiers, source_input, caller, workflow_def, final_answer) + else: + query_graph = message["query_graph"] + results_cache.set_lookup_result(workflow_def, query_graph, final_answer) # return the answer return final_answer, status_code From 7e22a8c35e46b73fabae4786b7ab6b412e32d456 Mon Sep 17 00:00:00 2001 From: Abrar Mesbah Date: Thu, 7 Dec 2023 13:44:52 -0500 Subject: [PATCH 02/13] change except --- src/service_aggregator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service_aggregator.py b/src/service_aggregator.py index f38f697..b75689b 100644 --- a/src/service_aggregator.py +++ b/src/service_aggregator.py @@ -187,7 +187,7 @@ async def entry(message, guid, coalesce_type, caller) -> (dict, int): if not override_cache: try: query_graph = message["query_graph"] - except: + except KeyError: return f"No query graph", 422 results = results_cache.get_lookup_result(workflow_def, query_graph) if results is not None: From cd00c84268df6c84c8f336446ce5dd13c59e1bcd Mon Sep 17 00:00:00 2001 From: Abrar Mesbah Date: Thu, 7 Dec 2023 15:31:30 -0500 Subject: [PATCH 03/13] change error code --- src/service_aggregator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service_aggregator.py b/src/service_aggregator.py index b75689b..6b716e6 100644 --- a/src/service_aggregator.py +++ b/src/service_aggregator.py @@ -188,7 +188,7 @@ async def entry(message, guid, coalesce_type, caller) -> (dict, int): try: query_graph = message["query_graph"] except KeyError: - return f"No query graph", 422 + return f"No query graph", 400 results = results_cache.get_lookup_result(workflow_def, query_graph) if results is not None: logger.info(f"{guid}: Returning results cache lookup") From def832efd1c4ff4d8f7d13a3fe88a23ce0e10c81 Mon Sep 17 00:00:00 2001 From: Abrar Mesbah Date: Thu, 7 Dec 2023 15:34:44 -0500 Subject: [PATCH 04/13] fix query_graph --- src/service_aggregator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/service_aggregator.py b/src/service_aggregator.py index 6b716e6..2b5ccf5 100644 --- a/src/service_aggregator.py +++ b/src/service_aggregator.py @@ -186,9 +186,9 @@ async def entry(message, guid, coalesce_type, caller) -> (dict, int): else: if not override_cache: try: - query_graph = message["query_graph"] + query_graph = message["message"]["query_graph"] except KeyError: - return f"No query graph", 400 + return f"No query graph", 422 results = results_cache.get_lookup_result(workflow_def, query_graph) if results is not None: logger.info(f"{guid}: Returning results cache lookup") From 8bc94993454519a19de905fc1e178c4391514f6b Mon Sep 17 00:00:00 2001 From: Abrar Mesbah Date: Thu, 7 Dec 2023 15:37:59 -0500 Subject: [PATCH 05/13] fix cache key --- src/results_cache.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/results_cache.py b/src/results_cache.py index a0c9188..01c1aed 100644 --- a/src/results_cache.py +++ b/src/results_cache.py @@ -41,7 +41,7 @@ def get_lookup_query_key(self, workflow, query_graph): return json.dumps(keydict, sort_keys=True) def get_lookup_result(self, workflow, query_graph): - key = self.get_query_key(workflow, query_graph) + key = self.get_lookup_query_key(workflow, query_graph) result = self.redis.get(key) if result is not None: result = json.loads(gzip.decompress(result)) @@ -49,7 +49,7 @@ def get_lookup_result(self, workflow, query_graph): def set_lookup_result(self, workflow, query_graph, final_answer): - key = self.get_query_key(workflow, query_graph) + key = self.get_lookup_query_key(workflow, query_graph) self.redis.set(key, gzip.compress(json.dumps(final_answer).encode())) From fa5f97ae42f732e82a5892accf72748af5c707df Mon Sep 17 00:00:00 2001 From: Abrar Mesbah Date: Fri, 8 Dec 2023 15:35:29 -0500 Subject: [PATCH 06/13] add redisMock --- requirements.txt | 3 ++- tests/helpers/redisMock.py | 10 ++++++++++ tests/test_aragorn.py | 8 ++++++-- tests/test_workflow.py | 8 ++++++-- 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 tests/helpers/redisMock.py diff --git a/requirements.txt b/requirements.txt index 26792af..7cee03d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,4 +19,5 @@ uvloop==0.17.0 opentelemetry-sdk==1.16.0 opentelemetry-instrumentation-fastapi==0.37b0 opentelemetry-exporter-jaeger==1.16.0 -opentelemetry-instrumentation-httpx==0.37b0 \ No newline at end of file +opentelemetry-instrumentation-httpx==0.37b0 +fakeredis<=2.10.2 \ No newline at end of file diff --git a/tests/helpers/redisMock.py b/tests/helpers/redisMock.py new file mode 100644 index 0000000..69a6f7f --- /dev/null +++ b/tests/helpers/redisMock.py @@ -0,0 +1,10 @@ +import fakeredis.aioredis as fakeredis +import gzip +import json + +async def redisMock(connection_pool=None): + # Here's where I got documentation for how to do async fakeredis: + # https://github.com/cunla/fakeredis-py/issues/66#issuecomment-1316045893 + redis = await fakeredis.FakeRedis() + # set up mock function + return redis \ No newline at end of file diff --git a/tests/test_aragorn.py b/tests/test_aragorn.py index cc08400..b20a1e0 100644 --- a/tests/test_aragorn.py +++ b/tests/test_aragorn.py @@ -1,5 +1,6 @@ import pytest from fastapi.testclient import TestClient +import redis.asyncio from src.server import APP import os import json @@ -7,6 +8,7 @@ from time import sleep from unittest.mock import patch from src.process_db import init_db +from tests.helpers.redisMock import redisMock client = TestClient(APP) @@ -46,7 +48,8 @@ def xtest_async(mock_callback): assert mock_callback.called -def test_aragorn_wf(): +def test_aragorn_wf(monkeypatch): + monkeypatch.setattr(redis.asyncio, "Redis", redisMock) init_db() workflow_A1("aragorn") @@ -296,7 +299,8 @@ def x_test_standup_2(): assert found -def test_null_results(): +def test_null_results(monkeypatch): + monkeypatch.setattr(redis.asyncio, "Redis", redisMock) init_db() #make sure that aragorn can handle cases where results is null (as opposed to missing) query= { diff --git a/tests/test_workflow.py b/tests/test_workflow.py index 9ca02d6..17a435e 100644 --- a/tests/test_workflow.py +++ b/tests/test_workflow.py @@ -1,5 +1,6 @@ import pytest from fastapi.testclient import TestClient +import redis.asyncio from src.server import APP as APP from src import operations import os @@ -7,11 +8,13 @@ from unittest.mock import patch from random import shuffle from src.process_db import init_db +from tests.helpers.redisMock import redisMock client = TestClient(APP) jsondir = 'InputJson_1.2' -def test_bad_ops(): +def test_bad_ops(monkeypatch): + monkeypatch.setattr(redis.asyncio, "Redis", redisMock) # get the location of the test file dir_path: str = os.path.dirname(os.path.realpath(__file__)) test_filename = os.path.join(dir_path, jsondir, 'workflow_422.json') @@ -25,8 +28,9 @@ def test_bad_ops(): # was the request successful assert(response.status_code == 422) -def test_lookup_only(): +def test_lookup_only(monkeypatch): """This has a workflow with a single op (lookup). So the result should not have scores""" + monkeypatch.setattr(redis.asyncio, "Redis", redisMock) init_db() dir_path: str = os.path.dirname(os.path.realpath(__file__)) test_filename = os.path.join(dir_path, jsondir, 'workflow_200.json') From 99f53b55be1ef9816b10ab3a8793534041240a3d Mon Sep 17 00:00:00 2001 From: Abrar Mesbah Date: Fri, 8 Dec 2023 15:40:37 -0500 Subject: [PATCH 07/13] update redis --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 7cee03d..7543b8d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ pytest-asyncio==0.15.1 pytest-dotenv==0.5.2 pyyaml==6.0 reasoner-pydantic==4.1.1 -redis~=3.5.3 +redis==4.3.4 requests==2.28.1 uvicorn==0.17.6 uvloop==0.17.0 @@ -20,4 +20,4 @@ opentelemetry-sdk==1.16.0 opentelemetry-instrumentation-fastapi==0.37b0 opentelemetry-exporter-jaeger==1.16.0 opentelemetry-instrumentation-httpx==0.37b0 -fakeredis<=2.10.2 \ No newline at end of file +fakeredis==2.10.2 \ No newline at end of file From fa7c3b499b60776558cd01037c4cfba427039b36 Mon Sep 17 00:00:00 2001 From: Abrar Mesbah Date: Fri, 8 Dec 2023 15:55:03 -0500 Subject: [PATCH 08/13] use strictredis --- tests/helpers/redisMock.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/helpers/redisMock.py b/tests/helpers/redisMock.py index 69a6f7f..ac33089 100644 --- a/tests/helpers/redisMock.py +++ b/tests/helpers/redisMock.py @@ -1,10 +1,10 @@ -import fakeredis.aioredis as fakeredis +import fakeredis import gzip import json async def redisMock(connection_pool=None): # Here's where I got documentation for how to do async fakeredis: # https://github.com/cunla/fakeredis-py/issues/66#issuecomment-1316045893 - redis = await fakeredis.FakeRedis() + redis = await fakeredis.FakeStrictRedis # set up mock function return redis \ No newline at end of file From 7715db10949145727af56e4d6a23d27b9604c5ad Mon Sep 17 00:00:00 2001 From: Abrar Mesbah Date: Fri, 8 Dec 2023 16:03:15 -0500 Subject: [PATCH 09/13] using strictredis --- requirements.txt | 4 ++-- tests/test_aragorn.py | 6 +++--- tests/test_workflow.py | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index 7543b8d..7cee03d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ pytest-asyncio==0.15.1 pytest-dotenv==0.5.2 pyyaml==6.0 reasoner-pydantic==4.1.1 -redis==4.3.4 +redis~=3.5.3 requests==2.28.1 uvicorn==0.17.6 uvloop==0.17.0 @@ -20,4 +20,4 @@ opentelemetry-sdk==1.16.0 opentelemetry-instrumentation-fastapi==0.37b0 opentelemetry-exporter-jaeger==1.16.0 opentelemetry-instrumentation-httpx==0.37b0 -fakeredis==2.10.2 \ No newline at end of file +fakeredis<=2.10.2 \ No newline at end of file diff --git a/tests/test_aragorn.py b/tests/test_aragorn.py index b20a1e0..e1ff74a 100644 --- a/tests/test_aragorn.py +++ b/tests/test_aragorn.py @@ -1,6 +1,6 @@ import pytest from fastapi.testclient import TestClient -import redis.asyncio +import redis from src.server import APP import os import json @@ -49,7 +49,7 @@ def xtest_async(mock_callback): def test_aragorn_wf(monkeypatch): - monkeypatch.setattr(redis.asyncio, "Redis", redisMock) + monkeypatch.setattr(redis, "Redis", redisMock) init_db() workflow_A1("aragorn") @@ -300,7 +300,7 @@ def x_test_standup_2(): assert found def test_null_results(monkeypatch): - monkeypatch.setattr(redis.asyncio, "Redis", redisMock) + monkeypatch.setattr(redis, "Redis", redisMock) init_db() #make sure that aragorn can handle cases where results is null (as opposed to missing) query= { diff --git a/tests/test_workflow.py b/tests/test_workflow.py index 17a435e..ee2a067 100644 --- a/tests/test_workflow.py +++ b/tests/test_workflow.py @@ -1,6 +1,6 @@ import pytest from fastapi.testclient import TestClient -import redis.asyncio +import redis from src.server import APP as APP from src import operations import os @@ -14,7 +14,7 @@ jsondir = 'InputJson_1.2' def test_bad_ops(monkeypatch): - monkeypatch.setattr(redis.asyncio, "Redis", redisMock) + monkeypatch.setattr(redis, "Redis", redisMock) # get the location of the test file dir_path: str = os.path.dirname(os.path.realpath(__file__)) test_filename = os.path.join(dir_path, jsondir, 'workflow_422.json') @@ -30,7 +30,7 @@ def test_bad_ops(monkeypatch): def test_lookup_only(monkeypatch): """This has a workflow with a single op (lookup). So the result should not have scores""" - monkeypatch.setattr(redis.asyncio, "Redis", redisMock) + monkeypatch.setattr(redis, "Redis", redisMock) init_db() dir_path: str = os.path.dirname(os.path.realpath(__file__)) test_filename = os.path.join(dir_path, jsondir, 'workflow_200.json') From 6be0daf6d6cc07f170b9fa898bf10a32bccaa8ef Mon Sep 17 00:00:00 2001 From: Max Wang Date: Mon, 11 Dec 2023 11:44:18 -0500 Subject: [PATCH 10/13] Fix tests --- src/service_aggregator.py | 11 +++++------ tests/helpers/redisMock.py | 4 ++-- tests/test_aragorn.py | 4 ++-- tests/test_workflow.py | 4 ++-- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/service_aggregator.py b/src/service_aggregator.py index 2b5ccf5..21dd3fd 100644 --- a/src/service_aggregator.py +++ b/src/service_aggregator.py @@ -165,6 +165,10 @@ async def entry(message, guid, coalesce_type, caller) -> (dict, int): # We told the world what we can do! # Workflow will be a list of the functions, and the parameters if there are any + try: + query_graph = message["message"]["query_graph"] + except KeyError: + return f"No query graph", 422 results_cache = ResultsCache() override_cache = (message.get("parameters") or {}).get("override_cache") override_cache = override_cache if type(override_cache) is bool else False @@ -185,10 +189,6 @@ async def entry(message, guid, coalesce_type, caller) -> (dict, int): logger.info(f"{guid}: Results cache miss") else: if not override_cache: - try: - query_graph = message["message"]["query_graph"] - except KeyError: - return f"No query graph", 422 results = results_cache.get_lookup_result(workflow_def, query_graph) if results is not None: logger.info(f"{guid}: Returning results cache lookup") @@ -210,8 +210,7 @@ async def entry(message, guid, coalesce_type, caller) -> (dict, int): if infer: results_cache.set_result(input_id, predicate, qualifiers, source_input, caller, workflow_def, final_answer) - else: - query_graph = message["query_graph"] + else: results_cache.set_lookup_result(workflow_def, query_graph, final_answer) # return the answer diff --git a/tests/helpers/redisMock.py b/tests/helpers/redisMock.py index ac33089..c67e6a3 100644 --- a/tests/helpers/redisMock.py +++ b/tests/helpers/redisMock.py @@ -2,9 +2,9 @@ import gzip import json -async def redisMock(connection_pool=None): +def redisMock(host=None, port=None, db=None, password=None): # Here's where I got documentation for how to do async fakeredis: # https://github.com/cunla/fakeredis-py/issues/66#issuecomment-1316045893 - redis = await fakeredis.FakeStrictRedis + redis = fakeredis.FakeStrictRedis() # set up mock function return redis \ No newline at end of file diff --git a/tests/test_aragorn.py b/tests/test_aragorn.py index e1ff74a..0b3a23e 100644 --- a/tests/test_aragorn.py +++ b/tests/test_aragorn.py @@ -49,7 +49,7 @@ def xtest_async(mock_callback): def test_aragorn_wf(monkeypatch): - monkeypatch.setattr(redis, "Redis", redisMock) + monkeypatch.setattr(redis, "StrictRedis", redisMock) init_db() workflow_A1("aragorn") @@ -300,7 +300,7 @@ def x_test_standup_2(): assert found def test_null_results(monkeypatch): - monkeypatch.setattr(redis, "Redis", redisMock) + monkeypatch.setattr(redis, "StrictRedis", redisMock) init_db() #make sure that aragorn can handle cases where results is null (as opposed to missing) query= { diff --git a/tests/test_workflow.py b/tests/test_workflow.py index ee2a067..d42f285 100644 --- a/tests/test_workflow.py +++ b/tests/test_workflow.py @@ -14,7 +14,7 @@ jsondir = 'InputJson_1.2' def test_bad_ops(monkeypatch): - monkeypatch.setattr(redis, "Redis", redisMock) + monkeypatch.setattr(redis, "StrictRedis", redisMock) # get the location of the test file dir_path: str = os.path.dirname(os.path.realpath(__file__)) test_filename = os.path.join(dir_path, jsondir, 'workflow_422.json') @@ -30,7 +30,7 @@ def test_bad_ops(monkeypatch): def test_lookup_only(monkeypatch): """This has a workflow with a single op (lookup). So the result should not have scores""" - monkeypatch.setattr(redis, "Redis", redisMock) + monkeypatch.setattr(redis, "StrictRedis", redisMock) init_db() dir_path: str = os.path.dirname(os.path.realpath(__file__)) test_filename = os.path.join(dir_path, jsondir, 'workflow_200.json') From 75c4bde0b1166e70954b4c4223316fcd8150d4f2 Mon Sep 17 00:00:00 2001 From: Max Wang Date: Mon, 11 Dec 2023 12:00:08 -0500 Subject: [PATCH 11/13] Put lookup queries in separate db --- src/aragorn_app.py | 15 +++++++++++++-- src/results_cache.py | 38 +++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/aragorn_app.py b/src/aragorn_app.py index 94ba4a3..aa945e5 100644 --- a/src/aragorn_app.py +++ b/src/aragorn_app.py @@ -188,12 +188,23 @@ class ClearCacheRequest(BaseModel): pswd: str -@ARAGORN_APP.post("/clear_cache", status_code=200, include_in_schema=False) +@ARAGORN_APP.post("/clear_creative_cache", status_code=200, include_in_schema=False) def clear_redis_cache(request: ClearCacheRequest) -> dict: """Clear the redis cache.""" if request.pswd == cache_password: cache = ResultsCache() - cache.clear_cache() + cache.clear_creative_cache() + return {"status": "success"} + else: + raise HTTPException(status_code=401, detail="Invalid Password") + + +@ARAGORN_APP.post("/clear_lookup_cache", status_code=200, include_in_schema=False) +def clear_redis_cache(request: ClearCacheRequest) -> dict: + """Clear the redis cache.""" + if request.pswd == cache_password: + cache = ResultsCache() + cache.clear_lookup_cache() return {"status": "success"} else: raise HTTPException(status_code=401, detail="Invalid Password") diff --git a/src/results_cache.py b/src/results_cache.py index 01c1aed..90d0975 100644 --- a/src/results_cache.py +++ b/src/results_cache.py @@ -5,16 +5,29 @@ CACHE_HOST = os.environ.get("CACHE_HOST", "localhost") CACHE_PORT = os.environ.get("CACHE_PORT", "6379") -CACHE_DB = os.environ.get("CACHE_DB", "0") -CACHE_PASSWORD = os.environ.get("CACHE_PASSWORD", "") +CREATIVE_CACHE_DB = os.environ.get("CREATIVE_CACHE_DB", "0") +LOOKUP_CACHE_DB = os.environ.get("LOOKUP_CACHE_DB", "1") class ResultsCache: - def __init__(self, redis_host=CACHE_HOST, redis_port=CACHE_PORT, redis_db=CACHE_DB, redis_password=CACHE_PASSWORD): + def __init__( + self, + redis_host=CACHE_HOST, + redis_port=CACHE_PORT, + creative_redis_db=CREATIVE_CACHE_DB, + lookup_redis_db=LOOKUP_CACHE_DB, + redis_password=CACHE_PASSWORD, + ): """Connect to cache.""" - self.redis = redis.StrictRedis( + self.creative_redis = redis.StrictRedis( host=redis_host, port=redis_port, - db=redis_db, + db=creative_redis_db, + password=redis_password, + ) + self.lookup_redis = redis.StrictRedis( + host=redis_host, + port=redis_port, + db=lookup_redis_db, password=redis_password, ) @@ -25,7 +38,7 @@ def get_query_key(self, input_id, predicate, qualifiers, source_input, caller, w def get_result(self, input_id, predicate, qualifiers, source_input, caller, workflow): key = self.get_query_key(input_id, predicate, qualifiers, source_input, caller, workflow) - result = self.redis.get(key) + result = self.creative_redis.get(key) if result is not None: result = json.loads(gzip.decompress(result)) return result @@ -34,7 +47,7 @@ def get_result(self, input_id, predicate, qualifiers, source_input, caller, work def set_result(self, input_id, predicate, qualifiers, source_input, caller, workflow, final_answer): key = self.get_query_key(input_id, predicate, qualifiers, source_input, caller, workflow) - self.redis.set(key, gzip.compress(json.dumps(final_answer).encode())) + self.creative_redis.set(key, gzip.compress(json.dumps(final_answer).encode())) def get_lookup_query_key(self, workflow, query_graph): keydict = {'workflow': workflow, 'query_graph': query_graph} @@ -42,7 +55,7 @@ def get_lookup_query_key(self, workflow, query_graph): def get_lookup_result(self, workflow, query_graph): key = self.get_lookup_query_key(workflow, query_graph) - result = self.redis.get(key) + result = self.lookup_redis.get(key) if result is not None: result = json.loads(gzip.decompress(result)) return result @@ -51,8 +64,11 @@ def get_lookup_result(self, workflow, query_graph): def set_lookup_result(self, workflow, query_graph, final_answer): key = self.get_lookup_query_key(workflow, query_graph) - self.redis.set(key, gzip.compress(json.dumps(final_answer).encode())) + self.lookup_redis.set(key, gzip.compress(json.dumps(final_answer).encode())) - def clear_cache(self): - self.redis.flushdb() + def clear_creative_cache(self): + self.creative_redis.flushdb() + + def clear_lookup_cache(self): + self.lookup_redis.flushdb() From f367a480d9d48ea8823dec61473bcad6ae3cc6d7 Mon Sep 17 00:00:00 2001 From: Max Wang Date: Mon, 11 Dec 2023 12:00:17 -0500 Subject: [PATCH 12/13] Bump minor version --- openapi-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi-config.yaml b/openapi-config.yaml index af213af..76f1f7a 100644 --- a/openapi-config.yaml +++ b/openapi-config.yaml @@ -11,7 +11,7 @@ servers: # url: http://127.0.0.1:5000 termsOfService: http://robokop.renci.org:7055/tos?service_long=ARAGORN&provider_long=RENCI title: ARAGORN -version: 2.5.2 +version: 2.6.0 tags: - name: translator - name: ARA From 7da76173cd9f96d435ff7733f187029a4b250b32 Mon Sep 17 00:00:00 2001 From: Max Wang Date: Mon, 11 Dec 2023 12:02:22 -0500 Subject: [PATCH 13/13] Add cache password back in --- src/results_cache.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/results_cache.py b/src/results_cache.py index 90d0975..2c9f105 100644 --- a/src/results_cache.py +++ b/src/results_cache.py @@ -7,6 +7,7 @@ CACHE_PORT = os.environ.get("CACHE_PORT", "6379") CREATIVE_CACHE_DB = os.environ.get("CREATIVE_CACHE_DB", "0") LOOKUP_CACHE_DB = os.environ.get("LOOKUP_CACHE_DB", "1") +CACHE_PASSWORD = os.environ.get("CACHE_PASSWORD", "") class ResultsCache: def __init__(