self._last_failure_msg = None
self._all_completions = dict()
self._completion_lock = Lock()
- self.inventory_cache = orchestrator.OutdatableDict(self, 'inventory_cache')
- self.service_cache = orchestrator.OutdatableDict(self, 'service_cache')
+ self.inventory_cache = orchestrator.OutdatableDict()
+ self.service_cache = orchestrator.OutdatableDict()
def available(self):
if not self._config_valid():
return 'OutdatableData(data={}, last_refresh={})'.format(self.data, self.last_refresh)
-class OutdatableDict(PersistentStoreDict):
+class OutdatableDictMixin(object):
"""
Toolbox for implementing a cache. As every orchestrator has
different needs, we cannot implement any logic here.
def __getitem__(self, item):
# type: (str) -> OutdatableData
- return OutdatableData.from_json(super(OutdatableDict, self).__getitem__(item))
+ return OutdatableData.from_json(super(OutdatableDictMixin, self).__getitem__(item))
def __setitem__(self, key, value):
# type: (str, OutdatableData) -> None
val = None if value is None else value.json()
- super(OutdatableDict, self).__setitem__(key, val)
+ super(OutdatableDictMixin, self).__setitem__(key, val)
def items(self):
# type: () -> Iterator[Tuple[str, OutdatableData]]
- for item in super(OutdatableDict, self).items():
+ for item in super(OutdatableDictMixin, self).items():
k, v = item
yield k, OutdatableData.from_json(v)
outdated = [item[0] for item in self.items() if item[1].outdated()]
for o in outdated:
del self[o]
+
+class OutdatablePersistentDict(OutdatableDictMixin, PersistentStoreDict):
+ pass
+
+class OutdatableDict(OutdatableDictMixin, dict):
+ pass
# cache is invalidated by
# 1. timeout
# 2. refresh parameter
- self.inventory_cache = orchestrator.OutdatableDict(self, self._STORE_HOST_PREFIX)
+ self.inventory_cache = orchestrator.OutdatablePersistentDict(self, self._STORE_HOST_PREFIX)
def handle_command(self, inbuf, command):
if command["prefix"] == "ssh set-ssh-config":