Cache

Cache(config: dict[str, Any])

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:
NameDescription
configA dictionary containing the cache configuration.

Type: dict[str, Any]

Class Attributes

ALLOWED_CONFIG_KEYS



Static Methods

cosmos_db

cosmos_db(
    connection_string: str | None = None,
    container_id: str | None = None,
    cache_seed: str | int = 42,
    client: any | None = None
) -> Cache

Create a Cosmos DB cache instance with ‘autogen_cache’ as database ID.

Parameters:
NameDescription
connection_stringConnection string to the Cosmos DB account.

Type: str | None

Default: None
container_idThe container ID for the Cosmos DB account.

Type: str | None

Default: None
cache_seedA seed for the cache.

Type: str | int

Default: 42
clientOptional[CosmosClient]: Pass an existing Cosmos DB client.

Type: any | None

Default: None
Returns:
TypeDescription
CacheCache: A Cache instance configured for Cosmos DB.

disk

disk(cache_seed: str | int = 42, cache_path_root: str = '.cache') -> autogen.Cache

Create a Disk cache instance.

Parameters:
NameDescription
cache_seedA seed for the cache.

Defaults to 42.

Type: str | int

Default: 42
cache_path_rootThe root path for the disk cache.

Defaults to “.cache”.

Type: str

Default: ‘.cache’
Returns:
TypeDescription
autogen.CacheCache: A Cache instance configured for Disk caching.

redis

redis(cache_seed: str | int = 42, redis_url: str = 'redis://localhost:6379/0') -> autogen.Cache

Create a Redis cache instance.

Parameters:
NameDescription
cache_seedA seed for the cache.

Defaults to 42.

Type: str | int

Default: 42
redis_urlThe URL for the Redis server.

Defaults to “redis://localhost:6379/0”.

Type: str

Default: ‘redis
Returns:
TypeDescription
autogen.CacheCache: A Cache instance configured for Redis.

Instance Methods

close

close(self) -> None

Close the cache.

Perform any necessary cleanup, such as closing connections or releasing resources.