Skip to content

CacheClient

CacheClient

CacheClient(table_name: str)

Bases: BaseClient

Client for caching data in memory, using the Singleton pattern.

This client stores data in a simple in-memory dictionary (_cache_data). It implements the BaseClient interface for common database operations, simulating database interactions by operating on the in-memory cache.

This class is designed for testing. It is NOT suitable for production environments.

Parameters:

Name Type Description Default
table_name str

The name of the table associated with the cache. While the table name isn't directly used for in-memory operations, it's stored for consistency with the BaseClient interface and may be used in future extensions of this class.

required
Source code in supadantic/clients/cache.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def __init__(self, table_name: str) -> None:
    """
    Initializes the client with the table name and an empty cache.

    Args:
        table_name (str): The name of the table associated with the cache.
                     While the table name isn't directly used for in-memory
                     operations, it's stored for consistency with the
                     `BaseClient` interface and may be used in future
                     extensions of this class.
    """
    super().__init__(table_name=table_name)

    self._cache_data: dict[int, dict[str, Any]] = {}