Debian Codegraph @

src/flask_caching/backends/base.py

raw
1 """
2 flask_caching.backends.base
3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5 This module contains the BaseCache that other caching
6 backends have to implement.
7
8 :copyright: (c) 2018 by Peter Justin.
9 :copyright: (c) 2010 by Thadeus Burgess.
10 :license: BSD, see LICENSE for more details.
11 """
12
13 from typing import Any
14
15 from cachelib import BaseCache as CachelibBaseCache
16 from flask import Flask
17
18
19 class BaseCache(CachelibBaseCache):
20 """Baseclass for the cache systems. All the cache systems implement this
21 API or a superset of it.
22
23 :param default_timeout: The default timeout (in seconds) that is used if
24 no timeout is specified on ``set``. A timeout
25 of 0 indicates that the cache never expires.
26 :param ignore_delete_many_errors: If set to ``False`` the ``delete_many``
27 method raises a ``RuntimeError`` in case
28 a key couldn't be deleted.
29 Defaults to ``False``.
30 """
31
32 def __init__(
33 self, default_timeout: int = 300, ignore_delete_many_errors: bool = False
34 ) -> None:
35 CachelibBaseCache.__init__(
36 self,
37 default_timeout=default_timeout,
38 ignore_delete_many_errors=ignore_delete_many_errors,
39 )
40
41 @classmethod
42 def factory(
43 cls,
44 app: Flask,
45 config: dict[str, Any],
46 args: list[Any],
47 kwargs: dict[str, Any],
48 ) -> "BaseCache":
49 return cls()