From 1d0d3784bb86f2e0175a47a7e6dbb2210bcc1b35 Mon Sep 17 00:00:00 2001 From: moecki <111915936+only-dev-time@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:43:22 +0200 Subject: [PATCH] fix #338 using of namespace in caching (#339) * fix #338 using of namespace in caching * add a keyword for ttl --- hive/server/db.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hive/server/db.py b/hive/server/db.py index 4d84aebd..dc4f6afa 100644 --- a/hive/server/db.py +++ b/hive/server/db.py @@ -33,7 +33,7 @@ def cacher(func): """Decorator for DB query result cache.""" async def _wrapper(*args, **kwargs): if 'cache_key' in kwargs and args[0].redis_cache is not None: - v = await args[0].redis_cache.get(kwargs["cache_key"]) + v = await args[0].redis_cache.get(kwargs["cache_key"], namespace=CACHE_NAMESPACE) if v is None: v = await func(*args, **kwargs) if v is None: @@ -63,9 +63,7 @@ async def _wrapper(*args, **kwargs): log.warning("[CACHE-LAYER] The row is not RowProxy. row: {%s}, args: {%s}, kwargs: {%s}", row, args, kwargs) a.append(row) v = a - cache_key = CACHE_NAMESPACE + kwargs['cache_key'] - await args[0].redis_cache.set(cache_key, v) - await args[0].redis_cache.expire(cache_key, ttl) + await args[0].redis_cache.set(kwargs['cache_key'], v, ttl=ttl, namespace=CACHE_NAMESPACE) return v else: return await func(*args, **kwargs)