Hopefully fixed a circular import
All checks were successful
Analysis / SonarCloud (push) Successful in 47s
All checks were successful
Analysis / SonarCloud (push) Successful in 47s
This commit is contained in:
24
src/libbot/cache/manager/manager.py
vendored
Normal file
24
src/libbot/cache/manager/manager.py
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
from typing import Dict, Any, Literal
|
||||
|
||||
from ..classes import CacheMemcached, CacheRedis
|
||||
|
||||
|
||||
def create_cache_client(
|
||||
config: Dict[str, Any],
|
||||
engine: Literal["memcached", "redis"] | None = None,
|
||||
) -> CacheMemcached | CacheRedis:
|
||||
if engine not in ["memcached", "redis"] or engine is None:
|
||||
raise KeyError(f"Incorrect cache engine provided. Expected 'memcached' or 'redis', got '{engine}'")
|
||||
|
||||
if "cache" not in config or engine not in config["cache"]:
|
||||
raise KeyError(
|
||||
f"Cache configuration is invalid. Please check if all keys are set (engine: '{engine}')"
|
||||
)
|
||||
|
||||
match engine:
|
||||
case "memcached":
|
||||
return CacheMemcached.from_config(config["cache"][engine])
|
||||
case "redis":
|
||||
return CacheRedis.from_config(config["cache"][engine])
|
||||
case _:
|
||||
raise KeyError(f"Cache implementation for the engine '{engine}' is not present.")
|
Reference in New Issue
Block a user