microblog.pub/utils/object_service.py

22 lines
532 B
Python
Raw Normal View History

2018-06-17 18:51:23 +00:00
import logging
2018-05-18 18:41:41 +00:00
2018-06-17 18:51:23 +00:00
from little_boxes.activitypub import get_backend
2018-06-16 20:02:10 +00:00
2018-06-17 18:51:23 +00:00
logger = logging.getLogger(__name__)
2018-05-25 22:03:30 +00:00
2018-05-18 18:41:41 +00:00
class ObjectService(object):
2018-06-17 18:51:23 +00:00
def __init__(self):
logger.debug("Initializing ObjectService")
self._cache = {}
2018-05-18 18:41:41 +00:00
2018-06-17 18:51:23 +00:00
def get(self, iri, reload_cache=False):
logger.info(f"get actor {iri} (reload_cache={reload_cache})")
2018-05-29 19:36:05 +00:00
2018-06-17 18:51:23 +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-17 18:51:23 +00:00
obj = get_backend().fetch_iri(iri)
self._cache[iri] = obj
2018-05-18 18:41:41 +00:00
return obj