Implemented memcached caching
This commit is contained in:
29
modules/cache_utils.py
Normal file
29
modules/cache_utils.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."
|
||||
)
|
@@ -38,3 +38,6 @@ sync_db: Database = db_client_sync.get_database(name=db_config["name"])
|
||||
sync_col_users: Collection = sync_db.get_collection("users")
|
||||
sync_col_warnings: Collection = sync_db.get_collection("warnings")
|
||||
sync_col_analytics: Collection = sync_db.get_collection("analytics")
|
||||
|
||||
# Update indexes
|
||||
sync_col_users.create_index(["id"], unique=True)
|
||||
|
Reference in New Issue
Block a user