File: null.py

package info (click to toggle)
python-dogpile.cache 1.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 772 kB
  • sloc: python: 5,462; makefile: 155; sh: 104
file content (66 lines) | stat: -rw-r--r-- 1,167 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
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
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
"""
Null Backend
-------------

The Null backend does not do any caching at all.  It can be
used to test behavior without caching, or as a means of disabling
caching for a region that is otherwise used normally.

.. versionadded:: 0.5.4

"""

from ..api import CacheBackend
from ..api import NO_VALUE


__all__ = ["NullBackend"]


class NullLock(object):
    def acquire(self, wait=True):
        return True

    def release(self):
        pass

    def locked(self):
        return False


class NullBackend(CacheBackend):
    """A "null" backend that effectively disables all cache operations.

    Basic usage::

        from dogpile.cache import make_region

        region = make_region().configure(
            'dogpile.cache.null'
        )

    """

    def __init__(self, arguments):
        pass

    def get_mutex(self, key):
        return NullLock()

    def get(self, key):
        return NO_VALUE

    def get_multi(self, keys):
        return [NO_VALUE for k in keys]

    def set(self, key, value):
        pass

    def set_multi(self, mapping):
        pass

    def delete(self, key):
        pass

    def delete_multi(self, keys):
        pass