File: base_cache.py

package info (click to toggle)
postfix-mta-sts-resolver 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 536 kB
  • sloc: python: 3,069; sh: 226; makefile: 47
file content (45 lines) | stat: -rw-r--r-- 1,151 bytes parent folder | download | duplicates (3)
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
import asyncio
import collections

from abc import ABC, abstractmethod


CacheEntry = collections.namedtuple('CacheEntry', ('ts', 'pol_id', 'pol_body'))


class BaseCache(ABC):
    @abstractmethod
    async def setup(self):
        """ Abstract method """

    @abstractmethod
    async def get(self, key):
        """ Abstract method """

    @abstractmethod
    async def set(self, key, value):
        """ Abstract method """

    async def safe_set(self, domain, entry, logger):
        try:
            await self.set(domain, entry)
        except asyncio.CancelledError:  # pragma: no cover pylint: disable=try-except-raise
            raise
        except Exception as exc:  # pragma: no cover
            logger.exception("Cache set failed: %s", str(exc))

    @abstractmethod
    async def scan(self, token, amount_hint):
        """ Abstract method """

    @abstractmethod
    async def get_proactive_fetch_ts(self):
        """ Abstract method """

    @abstractmethod
    async def set_proactive_fetch_ts(self, timestamp):
        """ Abstract method """

    @abstractmethod
    async def teardown(self):
        """ Abstract method """