storage.py
1 """ 2 Storing inventory items 3 """ 4 5 from abc import abstractmethod 6 from collections import namedtuple 7 try: 8 from collections import MutableMapping # pylint: disable=deprecated-class 9 except ImportError: 10 from collections.abc import MutableMapping 11 12 13 InventoryItem = namedtuple('InventoryItem', 'type stream payload expires tag') 14 15 16 class InventoryStorage(MutableMapping): 17 """ 18 Base class for storing inventory 19 (extendable for other items to store) 20 """ 21 22 def __init__(self): 23 self.numberOfInventoryLookupsPerformed = 0 24 25 @abstractmethod 26 def __contains__(self, item): 27 pass 28 29 @abstractmethod 30 def by_type_and_tag(self, objectType, tag): 31 """Return objects filtered by object type and tag""" 32 pass 33 34 @abstractmethod 35 def unexpired_hashes_by_stream(self, stream): 36 """Return unexpired inventory vectors filtered by stream""" 37 pass 38 39 @abstractmethod 40 def flush(self): 41 """Flush cache""" 42 pass 43 44 @abstractmethod 45 def clean(self): 46 """Free memory / perform garbage collection""" 47 pass