autogen.cache.cosmos_db_cache.CosmosDBCache
CosmosDBCache
Synchronous implementation of AbstractCache using Azure Cosmos DB NoSQL API.
This class provides a concrete implementation of the AbstractCache
interface using Azure Cosmos DB for caching data, with synchronous operations.
Attributes:
seed (Union[str, int]): A seed or namespace used as a partition key.
client (CosmosClient): The Cosmos DB client used for caching.
container: The container instance used for caching.
Initialize the CosmosDBCache instance.
Name | Description |
---|---|
seed | Type: str | int |
cosmosdb_config | Type: CosmosDBConfig |
Instance Methods
close
Close the Cosmos DB client.
Perform any necessary cleanup, such as closing network connections.
create_cache
Factory method to create a CosmosDBCache instance based on the provided configuration.
This method decides whether to use an existing CosmosClient or create a new one.
Name | Description |
---|---|
seed | Type: str | int |
cosmosdb_config | Type: CosmosDBConfig |
from_config
Name | Description |
---|---|
seed | Type: str | int |
cosmosdb_config | Type: CosmosDBConfig |
from_connection_string
Name | Description |
---|---|
seed | Type: str | int |
connection_string | Type: str |
database_id | Type: str |
container_id | Type: str |
from_existing_client
Name | Description |
---|---|
seed | Type: str | int |
client | Type: CosmosClient |
database_id | Type: str |
container_id | Type: str |
get
Retrieve an item from the Cosmos DB cache.
Name | Description |
---|---|
key | The key identifying the item in the cache. Type: str |
default | The default value to return if the key is not found. Type: Any | None Default: None |
Type | Description |
---|---|
Any | None | The deserialized value associated with the key if found, else the default value. |
set
Set an item in the Cosmos DB cache.
Name | Description |
---|---|
key | The key under which the item is to be stored. Type: str |
value | The value to be stored in the cache. Type: Any |