Skip to content

Commit

Permalink
fix #338 using of namespace in caching (#339)
Browse files Browse the repository at this point in the history
* fix #338 using of namespace in caching

* add a keyword for ttl
  • Loading branch information
only-dev-time authored Sep 23, 2024
1 parent 7ee5929 commit 1d0d378
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions hive/server/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1d0d378

Please sign in to comment.