summaryrefslogtreecommitdiff
path: root/src/mailman/interfaces/cache.py
blob: 39d3e7c735840a525b2c48e484cd0097426294fb (plain)
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
# Copyright (C) 2016 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
# GNU Mailman is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# GNU Mailman.  If not, see <http://www.gnu.org/licenses/>.

"""File caches."""

from public import public
from zope.interface import Interface


@public
class ICacheManager(Interface):
    """Manager for managing cached files."""

    def add(key, contents, lifetime=None):
        """Add the contents to the cache, indexed by the key.

        If there is already some contents cached under the given key, the old
        contents are overwritten with the new contents.

        :param key: The key to use when storing the contents.
        :type name: str
        :param contents: The contents to store in the cache.  If this is a
            bytes object, it will be stored on disk in binary.  If it's a str,
            it will be stored in UTF-8.  Either way, the manager will remember
            the type and return it when you access the file.
        :type contents: bytes or str
        :param lifetime: How long should the file be cached for, before it
            expires (leading to its eventual eviction)?  If not given, the
            system default lifetime is used.
        :type lifetime: datetime.timedelta
        :return: The SHA256 hash under which the file contents are stored.
        :rtype: str
        """

    def get(key, *, expunge=False):
        """Return the contents cached under the given key.

        :param key: The key identifying the contents you want to retrieve.
        :type key: str
        :param expunge: A flag indicating whether the file contents should
            also be removed from the cache.
        :type expunge: bool
        :return: The contents of the cached file or None if the given id isn't
            in the cache (or it's already expired).
        :rtype: bytes or str, depending on the original contents.
        """

    def evict():
        """Evict all files which have expired."""

    def clear():
        """Clear the entire cache of files."""