Skip to content

abc

cachetoolz.abc

Abstract module interface.

cachetoolz.abc.AsyncBackendABC

Bases: BaseBackend, ABC

Abstract async backend.

Attributes:

Name Type Description
logger logging.Logger

Package logger.

Source code in cachetoolz/abc/backend.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
class AsyncBackendABC(BaseBackend, ABC):
    """
    Abstract async backend.

    Attributes
    ----------
    logger : logging.Logger
        Package logger.
    """

    @abstractmethod
    async def get(self, key: str) -> Optional[str]:
        """
        Get a value if not expired.

        Parameters
        ----------
        key : str
            Cache identifier key.

        Returns
        -------
        with_cache : Any
            Value cached.
        without_cache : None
            If not exists or expired.
        """

    @abstractmethod
    async def set(self, key: str, value: str, expires_at: timedelta) -> None:
        """
        Set a value with expires time.

        Parameters
        ----------
        key : str
            Ccache identifier key.
        value : str
            Value to cache encoded.
        expires_at : datetime.timedelta
            Expiry time.
        """

    @abstractmethod
    async def clear(self, namespace: str) -> None:
        """
        Clear a namespace.

        Parameters
        ----------
        namespace : str
            Namespace to cache.
        """

get(key: str) -> Optional[str] abstractmethod async

Get a value if not expired.

Parameters:

Name Type Description Default
key str

Cache identifier key.

required

Returns:

Name Type Description
with_cache Any

Value cached.

without_cache None

If not exists or expired.

Source code in cachetoolz/abc/backend.py
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
@abstractmethod
async def get(self, key: str) -> Optional[str]:
    """
    Get a value if not expired.

    Parameters
    ----------
    key : str
        Cache identifier key.

    Returns
    -------
    with_cache : Any
        Value cached.
    without_cache : None
        If not exists or expired.
    """

set(key: str, value: str, expires_at: timedelta) -> None abstractmethod async

Set a value with expires time.

Parameters:

Name Type Description Default
key str

Ccache identifier key.

required
value str

Value to cache encoded.

required
expires_at datetime.timedelta

Expiry time.

required
Source code in cachetoolz/abc/backend.py
133
134
135
136
137
138
139
140
141
142
143
144
145
146
@abstractmethod
async def set(self, key: str, value: str, expires_at: timedelta) -> None:
    """
    Set a value with expires time.

    Parameters
    ----------
    key : str
        Ccache identifier key.
    value : str
        Value to cache encoded.
    expires_at : datetime.timedelta
        Expiry time.
    """

clear(namespace: str) -> None abstractmethod async

Clear a namespace.

Parameters:

Name Type Description Default
namespace str

Namespace to cache.

required
Source code in cachetoolz/abc/backend.py
148
149
150
151
152
153
154
155
156
157
@abstractmethod
async def clear(self, namespace: str) -> None:
    """
    Clear a namespace.

    Parameters
    ----------
    namespace : str
        Namespace to cache.
    """

cachetoolz.abc.BackendABC

Bases: BaseBackend, ABC

Abstract backend.

Attributes:

Name Type Description
logger logging.Logger

Package logger.

Source code in cachetoolz/abc/backend.py
 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
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
class BackendABC(BaseBackend, ABC):
    """
    Abstract backend.

    Attributes
    ----------
    logger : logging.Logger
        Package logger.
    """

    @abstractmethod
    def get(self, key: str) -> Optional[str]:
        """
        Get a value if not expired.

        Parameters
        ----------
        key : str
            Cache identifier key.

        Returns
        -------
        with_cache : Any
            Value cached.
        without_cache : None
            If not exists or expired.
        """

    @abstractmethod
    def set(self, key: str, value: str, expires_at: timedelta) -> None:
        """
        Set a value with expires time.

        Parameters
        ----------
        key : str
            Cache identifier key.
        value : str
            Value to cache encoded.
        expires_at : datetime.timedelta
            Expiry time.
        """

    @abstractmethod
    def clear(self, namespace: str) -> None:
        """
        Clear a namespace.

        Parameters
        ----------
        namespace : str
            Namespace to cache.
        """

get(key: str) -> Optional[str] abstractmethod

Get a value if not expired.

Parameters:

Name Type Description Default
key str

Cache identifier key.

required

Returns:

Name Type Description
with_cache Any

Value cached.

without_cache None

If not exists or expired.

Source code in cachetoolz/abc/backend.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
@abstractmethod
def get(self, key: str) -> Optional[str]:
    """
    Get a value if not expired.

    Parameters
    ----------
    key : str
        Cache identifier key.

    Returns
    -------
    with_cache : Any
        Value cached.
    without_cache : None
        If not exists or expired.
    """

set(key: str, value: str, expires_at: timedelta) -> None abstractmethod

Set a value with expires time.

Parameters:

Name Type Description Default
key str

Cache identifier key.

required
value str

Value to cache encoded.

required
expires_at datetime.timedelta

Expiry time.

required
Source code in cachetoolz/abc/backend.py
78
79
80
81
82
83
84
85
86
87
88
89
90
91
@abstractmethod
def set(self, key: str, value: str, expires_at: timedelta) -> None:
    """
    Set a value with expires time.

    Parameters
    ----------
    key : str
        Cache identifier key.
    value : str
        Value to cache encoded.
    expires_at : datetime.timedelta
        Expiry time.
    """

clear(namespace: str) -> None abstractmethod

Clear a namespace.

Parameters:

Name Type Description Default
namespace str

Namespace to cache.

required
Source code in cachetoolz/abc/backend.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
@abstractmethod
def clear(self, namespace: str) -> None:
    """
    Clear a namespace.

    Parameters
    ----------
    namespace : str
        Namespace to cache.
    """

cachetoolz.abc.CoderABC

Bases: ABC

Abstract coder.

Source code in cachetoolz/abc/coder.py
 7
 8
 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
class CoderABC(ABC):
    """Abstract coder."""

    @abstractmethod
    def encode(self, value: Any) -> Any:
        """
        Encode value.

        Parameters
        ----------
        value : Any
            Value to encode.

        Returns
        -------
        Any
            Value encoded.
        """

    @abstractmethod
    def decode(self, value: Any) -> Any:
        """
        Decode value.

        Parameters
        ----------
        value : Any
            Value to decode.

        Returns
        -------
        Any
            Value decoded.
        """

encode(value: Any) -> Any abstractmethod

Encode value.

Parameters:

Name Type Description Default
value Any

Value to encode.

required

Returns:

Type Description
Any

Value encoded.

Source code in cachetoolz/abc/coder.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
@abstractmethod
def encode(self, value: Any) -> Any:
    """
    Encode value.

    Parameters
    ----------
    value : Any
        Value to encode.

    Returns
    -------
    Any
        Value encoded.
    """

decode(value: Any) -> Any abstractmethod

Decode value.

Parameters:

Name Type Description Default
value Any

Value to decode.

required

Returns:

Type Description
Any

Value decoded.

Source code in cachetoolz/abc/coder.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@abstractmethod
def decode(self, value: Any) -> Any:
    """
    Decode value.

    Parameters
    ----------
    value : Any
        Value to decode.

    Returns
    -------
    Any
        Value decoded.
    """

cachetoolz.abc.SerializerABC

Bases: ABC

Abstract coder.

Source code in cachetoolz/abc/serializer.py
 7
 8
 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
class SerializerABC(ABC):
    """Abstract coder."""

    @abstractmethod
    def encode(self, value: Any) -> Any:
        """
        Encode value.

        Parameters
        ----------
        value : Any
            Value to encode.

        Returns
        -------
        Any
            Value encoded.
        """

    @abstractmethod
    def decode(self, value: Any) -> Any:
        """
        Decode value.

        Parameters
        ----------
        value : Any
            Value to decode.

        Returns
        -------
        Any
            Value decoded.
        """

encode(value: Any) -> Any abstractmethod

Encode value.

Parameters:

Name Type Description Default
value Any

Value to encode.

required

Returns:

Type Description
Any

Value encoded.

Source code in cachetoolz/abc/serializer.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
@abstractmethod
def encode(self, value: Any) -> Any:
    """
    Encode value.

    Parameters
    ----------
    value : Any
        Value to encode.

    Returns
    -------
    Any
        Value encoded.
    """

decode(value: Any) -> Any abstractmethod

Decode value.

Parameters:

Name Type Description Default
value Any

Value to decode.

required

Returns:

Type Description
Any

Value decoded.

Source code in cachetoolz/abc/serializer.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@abstractmethod
def decode(self, value: Any) -> Any:
    """
    Decode value.

    Parameters
    ----------
    value : Any
        Value to decode.

    Returns
    -------
    Any
        Value decoded.
    """