feat: adds usage logging and log key to the cache engine factory
This commit is contained in:
parent
97fcc15af5
commit
e8edf4482d
1 changed files with 6 additions and 3 deletions
|
|
@ -1,7 +1,6 @@
|
|||
"""Factory to get the appropriate cache coordination engine (e.g., Redis)."""
|
||||
|
||||
from functools import lru_cache
|
||||
import os
|
||||
from typing import Optional
|
||||
from cognee.infrastructure.databases.cache.config import get_cache_config
|
||||
from cognee.infrastructure.databases.cache.cache_db_interface import CacheDBInterface
|
||||
|
|
@ -17,6 +16,7 @@ def create_cache_engine(
|
|||
cache_username: str,
|
||||
cache_password: str,
|
||||
lock_key: str,
|
||||
log_key: str,
|
||||
agentic_lock_expire: int = 240,
|
||||
agentic_lock_timeout: int = 300,
|
||||
):
|
||||
|
|
@ -30,6 +30,7 @@ def create_cache_engine(
|
|||
- cache_username: Username to authenticate with.
|
||||
- cache_password: Password to authenticate with.
|
||||
- lock_key: Identifier used for the locking resource.
|
||||
- log_key: Identifier used for usage logging.
|
||||
- agentic_lock_expire: Duration to hold the lock after acquisition.
|
||||
- agentic_lock_timeout: Max time to wait for the lock before failing.
|
||||
|
||||
|
|
@ -37,7 +38,7 @@ def create_cache_engine(
|
|||
--------
|
||||
- CacheDBInterface: An instance of the appropriate cache adapter.
|
||||
"""
|
||||
if config.caching:
|
||||
if config.caching or config.usage_logging:
|
||||
from cognee.infrastructure.databases.cache.redis.RedisAdapter import RedisAdapter
|
||||
|
||||
if config.cache_backend == "redis":
|
||||
|
|
@ -47,6 +48,7 @@ def create_cache_engine(
|
|||
username=cache_username,
|
||||
password=cache_password,
|
||||
lock_name=lock_key,
|
||||
log_key=log_key,
|
||||
timeout=agentic_lock_expire,
|
||||
blocking_timeout=agentic_lock_timeout,
|
||||
)
|
||||
|
|
@ -61,7 +63,7 @@ def create_cache_engine(
|
|||
return None
|
||||
|
||||
|
||||
def get_cache_engine(lock_key: Optional[str] = None) -> CacheDBInterface:
|
||||
def get_cache_engine(lock_key: Optional[str] = None, log_key: Optional[str] = None) -> CacheDBInterface:
|
||||
"""
|
||||
Returns a cache adapter instance using current context configuration.
|
||||
"""
|
||||
|
|
@ -72,6 +74,7 @@ def get_cache_engine(lock_key: Optional[str] = None) -> CacheDBInterface:
|
|||
cache_username=config.cache_username,
|
||||
cache_password=config.cache_password,
|
||||
lock_key=lock_key,
|
||||
log_key=log_key,
|
||||
agentic_lock_expire=config.agentic_lock_expire,
|
||||
agentic_lock_timeout=config.agentic_lock_timeout,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue