v0.2.0 #26
@ -5,7 +5,7 @@ from libbot.pycord.classes import PycordBot
|
||||
|
||||
from classes.cache.holo_cache_memcached import HoloCacheMemcached
|
||||
from classes.cache.holo_cache_redis import HoloCacheRedis
|
||||
from modules.cache_utils import create_cache_client
|
||||
from modules.cache_manager import create_cache_client
|
||||
|
||||
logger: Logger = logging.getLogger(__name__)
|
||||
|
||||
|
29
modules/cache_manager.py
Normal file
29
modules/cache_manager.py
Normal file
@ -0,0 +1,29 @@
|
||||
from typing import Dict, Any, Literal
|
||||
|
||||
from classes.cache.holo_cache_memcached import HoloCacheMemcached
|
||||
from classes.cache.holo_cache_redis import HoloCacheRedis
|
||||
|
||||
|
||||
def create_cache_client(
|
||||
config: Dict[str, Any],
|
||||
engine: Literal["memcached", "redis"] | None = None,
|
||||
) -> HoloCacheMemcached | HoloCacheRedis:
|
||||
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 HoloCacheMemcached.from_config(config["cache"][engine])
|
||||
case "redis":
|
||||
return HoloCacheRedis.from_config(config["cache"][engine])
|
||||
case _:
|
||||
raise KeyError(
|
||||
f"Cache implementation for the engine '{engine}' is not present."
|
||||
)
|
@ -1,37 +1,9 @@
|
||||
from copy import deepcopy
|
||||
from typing import Dict, Any, Literal
|
||||
from typing import Any
|
||||
|
||||
from bson import ObjectId
|
||||
from ujson import dumps, loads
|
||||
|
||||
from classes.cache.holo_cache_memcached import HoloCacheMemcached
|
||||
from classes.cache.holo_cache_redis import HoloCacheRedis
|
||||
|
||||
|
||||
def create_cache_client(
|
||||
config: Dict[str, Any],
|
||||
engine: Literal["memcached", "redis"] | None = None,
|
||||
) -> HoloCacheMemcached | HoloCacheRedis:
|
||||
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 HoloCacheMemcached.from_config(config["cache"][engine])
|
||||
case "redis":
|
||||
return HoloCacheRedis.from_config(config["cache"][engine])
|
||||
case _:
|
||||
raise KeyError(
|
||||
f"Cache implementation for the engine '{engine}' is not present."
|
||||
)
|
||||
|
||||
|
||||
def json_to_string(json_object: Any) -> str:
|
||||
json_object_copy: Any = deepcopy(json_object)
|
||||
|
Loading…
x
Reference in New Issue
Block a user