Skip to content

Base

BaseCache

Bases: ABC

Abstract base class for cache backends.

Attributes:

Name Type Description
client CacheClient

Cache client instance.

Source code in dynamiq/cache/backends/base.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
class BaseCache(ABC):
    """Abstract base class for cache backends.

    Attributes:
        client (CacheClient): Cache client instance.
    """

    def __init__(self, client: CacheClient):
        """Initialize BaseCache.

        Args:
            client (CacheClient): Cache client instance.
        """
        self.client = client

    @classmethod
    def from_client(cls, client: CacheClient):
        """Create cache instance from client.

        Args:
            client (CacheClient): Cache client instance.

        Returns:
            BaseCache: Cache instance.
        """
        return cls(client=client)

    @classmethod
    @abstractmethod
    def from_config(cls, config: CacheConfig):
        """Create cache instance from configuration.

        Args:
            config (CacheConfig): Cache configuration.

        Raises:
            NotImplementedError: If not implemented.
        """
        raise NotImplementedError

    @abstractmethod
    def get(self, key: str):
        """Retrieve value from cache.

        Args:
            key (str): Cache key.

        Raises:
            NotImplementedError: If not implemented.
        """
        raise NotImplementedError

    @abstractmethod
    def set(self, key: str, value: dict):
        """Set value in cache.

        Args:
            key (str): Cache key.
            value (dict): Value to cache.

        Raises:
            NotImplementedError: If not implemented.
        """
        raise NotImplementedError

    @abstractmethod
    def delete(self, key: str):
        """Delete value from cache.

        Args:
            key (str): Cache key.

        Raises:
            NotImplementedError: If not implemented.
        """
        raise NotImplementedError

__init__(client)

Initialize BaseCache.

Parameters:

Name Type Description Default
client CacheClient

Cache client instance.

required
Source code in dynamiq/cache/backends/base.py
16
17
18
19
20
21
22
def __init__(self, client: CacheClient):
    """Initialize BaseCache.

    Args:
        client (CacheClient): Cache client instance.
    """
    self.client = client

delete(key) abstractmethod

Delete value from cache.

Parameters:

Name Type Description Default
key str

Cache key.

required

Raises:

Type Description
NotImplementedError

If not implemented.

Source code in dynamiq/cache/backends/base.py
74
75
76
77
78
79
80
81
82
83
84
@abstractmethod
def delete(self, key: str):
    """Delete value from cache.

    Args:
        key (str): Cache key.

    Raises:
        NotImplementedError: If not implemented.
    """
    raise NotImplementedError

from_client(client) classmethod

Create cache instance from client.

Parameters:

Name Type Description Default
client CacheClient

Cache client instance.

required

Returns:

Name Type Description
BaseCache

Cache instance.

Source code in dynamiq/cache/backends/base.py
24
25
26
27
28
29
30
31
32
33
34
@classmethod
def from_client(cls, client: CacheClient):
    """Create cache instance from client.

    Args:
        client (CacheClient): Cache client instance.

    Returns:
        BaseCache: Cache instance.
    """
    return cls(client=client)

from_config(config) abstractmethod classmethod

Create cache instance from configuration.

Parameters:

Name Type Description Default
config CacheConfig

Cache configuration.

required

Raises:

Type Description
NotImplementedError

If not implemented.

Source code in dynamiq/cache/backends/base.py
36
37
38
39
40
41
42
43
44
45
46
47
@classmethod
@abstractmethod
def from_config(cls, config: CacheConfig):
    """Create cache instance from configuration.

    Args:
        config (CacheConfig): Cache configuration.

    Raises:
        NotImplementedError: If not implemented.
    """
    raise NotImplementedError

get(key) abstractmethod

Retrieve value from cache.

Parameters:

Name Type Description Default
key str

Cache key.

required

Raises:

Type Description
NotImplementedError

If not implemented.

Source code in dynamiq/cache/backends/base.py
49
50
51
52
53
54
55
56
57
58
59
@abstractmethod
def get(self, key: str):
    """Retrieve value from cache.

    Args:
        key (str): Cache key.

    Raises:
        NotImplementedError: If not implemented.
    """
    raise NotImplementedError

set(key, value) abstractmethod

Set value in cache.

Parameters:

Name Type Description Default
key str

Cache key.

required
value dict

Value to cache.

required

Raises:

Type Description
NotImplementedError

If not implemented.

Source code in dynamiq/cache/backends/base.py
61
62
63
64
65
66
67
68
69
70
71
72
@abstractmethod
def set(self, key: str, value: dict):
    """Set value in cache.

    Args:
        key (str): Cache key.
        value (dict): Value to cache.

    Raises:
        NotImplementedError: If not implemented.
    """
    raise NotImplementedError