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 cachelib import BaseCache as CachelibBaseCache
14
15
16 class BaseCache(CachelibBaseCache):
17 """Baseclass for the cache systems. All the cache systems implement this
18 API or a superset of it.
19
20 :param default_timeout: The default timeout (in seconds) that is used if
21 no timeout is specified on :meth:`set`. A timeout
22 of 0 indicates that the cache never expires.
23 """
24
25 def __init__(self, default_timeout=300):
26 CachelibBaseCache.__init__(self, default_timeout=default_timeout)
27 self.ignore_errors = False
28
29 @classmethod
30 def factory(cls, app, config, args, kwargs):
31 return cls()
32
33 def delete_many(self, *keys):
34 """Deletes multiple keys at once.
35
36 :param keys: The function accepts multiple keys as positional
37 arguments.
38 :returns: A list containing all sucessfuly deleted keys
39 :rtype: boolean
40 """
41 deleted_keys = []
42 for key in keys:
43 if self.delete(key):
44 deleted_keys.append(key)
45 else:
46 if not self.ignore_errors:
47 break
48 return deleted_keys