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 """
|