<!-- .github/pull_request_template.md --> ## Description This PR introduces a shared locked mechanism in KuzuAdapter to avoid use case when multiple subprocesses from different environments are trying to use the same Kuzu adatabase. ## Type of Change <!-- Please check the relevant option --> - [ ] Bug fix (non-breaking change that fixes an issue) - [x] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Code refactoring - [x] Performance improvement - [ ] Other (please specify): ## Screenshots/Videos (if applicable) None ## Pre-submission Checklist <!-- Please check all boxes that apply before submitting your PR --> - [x] **I have tested my changes thoroughly before submitting this PR** - [x] **This PR contains minimal changes necessary to address the issue/feature** - [x] My code follows the project's coding standards and style guidelines - [x] I have added tests that prove my fix is effective or that my feature works - [x] I have added necessary documentation (if applicable) - [x] All new and existing tests pass - [x] I have searched existing PRs to ensure this change hasn't been submitted already - [x] I have linked any relevant issues in the description - [x] My commits have clear and descriptive messages ## DCO Affirmation I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin.
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
from functools import lru_cache
|
|
|
|
|
|
class CacheConfig(BaseSettings):
|
|
"""
|
|
Configuration for distributed cache systems (e.g., Redis), used for locking or coordination.
|
|
|
|
Attributes:
|
|
- shared_kuzu_lock: Shared kuzu lock logic on/off.
|
|
- cache_host: Hostname of the cache service.
|
|
- cache_port: Port number for the cache service.
|
|
- agentic_lock_expire: Automatic lock expiration time (in seconds).
|
|
- agentic_lock_timeout: Maximum time (in seconds) to wait for the lock release.
|
|
"""
|
|
|
|
caching: bool = False
|
|
shared_kuzu_lock: bool = False
|
|
cache_host: str = "localhost"
|
|
cache_port: int = 6379
|
|
agentic_lock_expire: int = 240
|
|
agentic_lock_timeout: int = 300
|
|
|
|
model_config = SettingsConfigDict(env_file=".env", extra="allow")
|
|
|
|
def to_dict(self) -> dict:
|
|
return {
|
|
"caching": self.caching,
|
|
"shared_kuzu_lock": self.shared_kuzu_lock,
|
|
"cache_host": self.cache_host,
|
|
"cache_port": self.cache_port,
|
|
"agentic_lock_expire": self.agentic_lock_expire,
|
|
"agentic_lock_timeout": self.agentic_lock_timeout,
|
|
}
|
|
|
|
|
|
@lru_cache
|
|
def get_cache_config():
|
|
return CacheConfig()
|