pre-commit changes
This commit is contained in:
13
App/cache/wrapper.py
vendored
13
App/cache/wrapper.py
vendored
@@ -1,15 +1,18 @@
|
||||
from functools import wraps
|
||||
|
||||
from . import RedisCache
|
||||
|
||||
|
||||
def fetch_from_cache(cache_name: str, cache_config: dict):
|
||||
cache_conn = RedisCache(cache_config['redis'])
|
||||
ttl = cache_config['ttl']
|
||||
cache_conn = RedisCache(cache_config["redis"])
|
||||
ttl = cache_config["ttl"]
|
||||
|
||||
"""
|
||||
It checks if a cached value exists for a given cache_name.
|
||||
If a cached value exists, it returns the cached value.
|
||||
If no cached value exists, it calls the original function f with the provided arguments, caches the result, and then returns the result.
|
||||
"""
|
||||
|
||||
def decorator(f):
|
||||
@wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
@@ -19,7 +22,9 @@ def fetch_from_cache(cache_name: str, cache_config: dict):
|
||||
return cached_value
|
||||
response = f(*args, **kwargs)
|
||||
print("response=", response)
|
||||
cache_conn.set_value(cache_name,response,ttl)
|
||||
cache_conn.set_value(cache_name, response, ttl)
|
||||
return response
|
||||
|
||||
return wrapper
|
||||
return decorator
|
||||
|
||||
return decorator
|
||||
|
||||
Reference in New Issue
Block a user