Skip to content

base

langroid/cachedb/base.py

CacheDB

Bases: ABC

Abstract base class for a cache database.

store(key, value) abstractmethod

Abstract method to store a value associated with a key.

Parameters:

Name Type Description Default
key str

The key under which to store the value.

required
value dict

The value to store.

required
Source code in langroid/cachedb/base.py
@abstractmethod
def store(self, key: str, value: Dict[str, Any]) -> None:
    """
    Abstract method to store a value associated with a key.

    Args:
        key (str): The key under which to store the value.
        value (dict): The value to store.
    """
    pass

retrieve(key) abstractmethod

Abstract method to retrieve the value associated with a key.

Parameters:

Name Type Description Default
key str

The key to retrieve the value for.

required

Returns:

Name Type Description
dict Dict[str, Any] | str | None

The value associated with the key.

Source code in langroid/cachedb/base.py
@abstractmethod
def retrieve(self, key: str) -> Dict[str, Any] | str | None:
    """
    Abstract method to retrieve the value associated with a key.

    Args:
        key (str): The key to retrieve the value for.

    Returns:
        dict: The value associated with the key.
    """
    pass

delete_keys(keys) abstractmethod

Delete the keys from the cache.

Parameters:

Name Type Description Default
keys List[str]

The keys to delete.

required
Source code in langroid/cachedb/base.py
@abstractmethod
def delete_keys(self, keys: List[str]) -> None:
    """
    Delete the keys from the cache.

    Args:
        keys (List[str]): The keys to delete.
    """
    pass

delete_keys_pattern(pattern) abstractmethod

Delete all keys with the given pattern

Parameters:

Name Type Description Default
prefix str

The pattern to match.

required
Source code in langroid/cachedb/base.py
@abstractmethod
def delete_keys_pattern(self, pattern: str) -> None:
    """
    Delete all keys with the given pattern

    Args:
        prefix (str): The pattern to match.
    """
    pass