cic-internal-integration/apps/cic-ussd/cic_ussd/metadata/base.py

33 lines
926 B
Python
Raw Normal View History

2021-04-14 11:00:10 +02:00
# standard imports
import logging
2021-10-15 13:21:41 +02:00
# external imports
from cic_types.condiments import MetadataPointer
from cic_types.ext.metadata import MetadataRequestsHandler
from cic_types.processor import generate_metadata_pointer
2021-04-14 11:00:10 +02:00
# local imports
2021-08-06 18:29:01 +02:00
from cic_ussd.cache import cache_data, get_cached_data
2021-04-14 11:00:10 +02:00
2021-08-06 18:29:01 +02:00
logg = logging.getLogger(__file__)
2021-04-14 11:00:10 +02:00
2021-10-15 13:21:41 +02:00
class UssdMetadataHandler(MetadataRequestsHandler):
2021-10-25 20:03:18 +02:00
def __init__(self, identifier: bytes, cic_type: MetadataPointer = None):
2021-10-15 13:21:41 +02:00
super().__init__(cic_type, identifier)
2021-10-15 13:21:41 +02:00
def cache_metadata(self, data: str):
"""
:param data:
:type data:
:return:
:rtype:
"""
cache_data(self.metadata_pointer, data)
logg.debug(f'caching: {data} with key: {self.metadata_pointer}')
2021-08-06 18:29:01 +02:00
def get_cached_metadata(self):
""""""
key = generate_metadata_pointer(self.identifier, self.cic_type)
return get_cached_data(key)