Added support for cache prefix
All checks were successful
Analysis / SonarCloud (push) Successful in 54s
Analysis / SonarCloud (pull_request) Successful in 46s
Tests / Build and Test (3.11) (pull_request) Successful in 1m12s
Tests / Build and Test (3.12) (pull_request) Successful in 1m9s
Tests / Build and Test (3.13) (pull_request) Successful in 1m6s
All checks were successful
Analysis / SonarCloud (push) Successful in 54s
Analysis / SonarCloud (pull_request) Successful in 46s
Tests / Build and Test (3.11) (pull_request) Successful in 1m12s
Tests / Build and Test (3.12) (pull_request) Successful in 1m9s
Tests / Build and Test (3.13) (pull_request) Successful in 1m6s
This commit is contained in:
7
src/libbot/cache/manager/manager.py
vendored
7
src/libbot/cache/manager/manager.py
vendored
@@ -1,4 +1,4 @@
|
||||
from typing import Dict, Any, Literal
|
||||
from typing import Dict, Any, Literal, Optional
|
||||
|
||||
from ..classes import CacheMemcached, CacheRedis
|
||||
|
||||
@@ -6,6 +6,7 @@ from ..classes import CacheMemcached, CacheRedis
|
||||
def create_cache_client(
|
||||
config: Dict[str, Any],
|
||||
engine: Literal["memcached", "redis"] | None = None,
|
||||
prefix: Optional[str] = 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}'")
|
||||
@@ -17,8 +18,8 @@ def create_cache_client(
|
||||
|
||||
match engine:
|
||||
case "memcached":
|
||||
return CacheMemcached.from_config(config["cache"][engine])
|
||||
return CacheMemcached.from_config(config["cache"][engine], prefix=prefix)
|
||||
case "redis":
|
||||
return CacheRedis.from_config(config["cache"][engine])
|
||||
return CacheRedis.from_config(config["cache"][engine], prefix=prefix)
|
||||
case _:
|
||||
raise KeyError(f"Cache implementation for the engine '{engine}' is not present.")
|
||||
|
Reference in New Issue
Block a user