diff --git a/selfprivacy_api/utils/cached_call.py b/selfprivacy_api/utils/cached_call.py index 6fbdd55..92d973d 100644 --- a/selfprivacy_api/utils/cached_call.py +++ b/selfprivacy_api/utils/cached_call.py @@ -8,21 +8,21 @@ from selfprivacy_api.utils.redis_pool import RedisPool CACHE_PREFIX = "exec_cache:" -async def get_redis_object(key: str) -> Optional[Any]: - redis = RedisPool().get_connection_async() - binary_obj = await redis.get(key) +def get_redis_object(key: str) -> Optional[Any]: + redis = RedisPool().get_connection() + binary_obj = redis.get(key) if binary_obj is None: return None return pickle.loads(binary_obj) -async def save_redis_object(key: str, obj: Any, expire: Optional[int] = 60) -> None: - redis = RedisPool().get_connection_async() +def save_redis_object(key: str, obj: Any, expire: Optional[int] = 60) -> None: + redis = RedisPool().get_connection() binary_obj = pickle.dumps(obj) if expire: - await redis.setex(key, expire, binary_obj) + redis.setex(key, expire, binary_obj) else: - await redis.set(key, binary_obj) + redis.set(key, binary_obj) def redis_cached_call(ttl: Optional[int] = 60) -> Callable[..., Callable]: @@ -30,16 +30,13 @@ def redis_cached_call(ttl: Optional[int] = 60) -> Callable[..., Callable]: @wraps(func) async def wrapper(*args, **kwargs) -> Any: key = f"{CACHE_PREFIX}{func.__name__}:{args}:{kwargs}" - cached_value = await get_redis_object(key) + cached_value = get_redis_object(key) if cached_value is not None: return cached_value - if asyncio.iscoroutinefunction(func): - result = await func(*args, **kwargs) - else: - result = func(*args, **kwargs) + result = func(*args, **kwargs) - await save_redis_object(key, result, ttl) + save_redis_object(key, result, ttl) return result