microblog.pub/utils/object_service.py

22 lines
532 B
Python
Raw Normal View History

2018-06-18 22:10:19 +00:00
import logging
2018-05-18 18:41:41 +00:00
2018-06-18 22:10:19 +00:00
from little_boxes.activitypub import get_backend
2018-05-25 22:03:30 +00:00
2018-06-18 22:10:19 +00:00
logger = logging.getLogger(__name__)
2018-05-18 18:41:41 +00:00
2018-06-18 22:10:19 +00:00
class ObjectService(object):
def __init__(self):
logger.debug("Initializing ObjectService")
self._cache = {}
2018-05-18 18:41:41 +00:00
2018-06-18 22:10:19 +00:00
def get(self, iri, reload_cache=False):
logger.info(f"get actor {iri} (reload_cache={reload_cache})")
2018-05-18 18:41:41 +00:00
2018-06-18 22:10:19 +00:00
if not reload_cache and iri in self._cache:
return self._cache[iri]
2018-05-18 18:41:41 +00:00
2018-06-18 22:10:19 +00:00
obj = get_backend().fetch_iri(iri)
self._cache[iri] = obj
2018-05-18 18:41:41 +00:00
return obj