This repository has been archived on 2025-02-01. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2025-02-01/src/storage/storage.py

48 lines
1.1 KiB
Python
Raw Normal View History

2019-09-26 10:42:15 +02:00
"""
2019-12-24 13:53:48 +01:00
Storing inventory items
2019-09-26 10:42:15 +02:00
"""
2023-11-21 12:29:08 +01:00
from abc import abstractmethod
from collections import namedtuple
try:
from collections import MutableMapping # pylint: disable=deprecated-class
except ImportError:
from collections.abc import MutableMapping
2019-09-25 13:09:15 +02:00
InventoryItem = namedtuple('InventoryItem', 'type stream payload expires tag')
2019-09-25 13:09:15 +02:00
class InventoryStorage(MutableMapping):
"""
Base class for storing inventory
(extendable for other items to store)
"""
2019-12-24 13:53:48 +01:00
def __init__(self):
self.numberOfInventoryLookupsPerformed = 0
@abstractmethod
def __contains__(self, item):
pass
@abstractmethod
2017-06-24 12:13:35 +02:00
def by_type_and_tag(self, objectType, tag):
2019-09-24 11:20:20 +02:00
"""Return objects filtered by object type and tag"""
pass
@abstractmethod
def unexpired_hashes_by_stream(self, stream):
2019-09-24 11:20:20 +02:00
"""Return unexpired inventory vectors filtered by stream"""
pass
@abstractmethod
def flush(self):
2019-09-24 11:20:20 +02:00
"""Flush cache"""
pass
@abstractmethod
def clean(self):
2019-09-24 11:20:20 +02:00
"""Free memory / perform garbage collection"""
pass