autogen.Cache
Cache
A wrapper class for managing cache configuration and instances.
This class provides a unified interface for creating and interacting with different types of cache (e.g., Redis, Disk). It abstracts the underlying cache implementation details, providing methods for cache operations.
Attributes: config (Dict[str, Any]): A dictionary containing cache configuration. cache: The cache instance created based on the provided configuration.
Initialize the Cache with the given configuration.
Validates the configuration keys and creates the cache instance.
Parameters:Name | Description |
---|---|
config | A dictionary containing the cache configuration. Type: dict[str, Any] |
Class Attributes
ALLOWED_CONFIG_KEYS
Static Methods
cosmos_db
Create a Cosmos DB cache instance with ‘autogen_cache’ as database ID.
Parameters:Name | Description |
---|---|
connection_string | Connection string to the Cosmos DB account. Type: str | None Default: None |
container_id | The container ID for the Cosmos DB account. Type: str | None Default: None |
cache_seed | A seed for the cache. Type: str | int Default: 42 |
client | Optional[CosmosClient]: Pass an existing Cosmos DB client. Type: any | None Default: None |
Type | Description |
---|---|
Cache | Cache: A Cache instance configured for Cosmos DB. |
disk
Create a Disk cache instance.
Parameters:Name | Description |
---|---|
cache_seed | A seed for the cache. Defaults to 42. Type: str | int Default: 42 |
cache_path_root | The root path for the disk cache. Defaults to “.cache”. Type: str Default: ‘.cache’ |
Type | Description |
---|---|
autogen.Cache | Cache: A Cache instance configured for Disk caching. |
redis
Create a Redis cache instance.
Parameters:Name | Description |
---|---|
cache_seed | A seed for the cache. Defaults to 42. Type: str | int Default: 42 |
redis_url | The URL for the Redis server. Defaults to “redis://localhost:6379/0”. Type: str Default: ‘redis |
Type | Description |
---|---|
autogen.Cache | Cache: A Cache instance configured for Redis. |
Instance Methods
close
Close the cache.
Perform any necessary cleanup, such as closing connections or releasing resources.