INNER CODE UNIT · Python
Backup
opentimestamps/opentimestamps-server · otsserver/backup.py:34
class Backup:
def __init__(self, journal, calendar, cache_path):
self.journal = journal
self.calendar = calendar
self.cache_path = cache_path
os.makedirs(cache_path, exist_ok=True)
# Return the bytes of the chunk
def __getitem__(self, chunk):
# We use a disk cache, creating a chunk of 1000 commitments is a quite expensive operation of about 10s.
# The server isn't blocked in the meantime but this could be used by an attacker to degrade calendar performance
# Moreover is not recommended to set up an HTTP cache more than one year (see RFC 2616), thus, a disk cache is
# mandatory.
cached_kv_bytes = self.read_disk_cache(chunk)
if cached_kv_bytes is not None:
return cached_kv_bytes