def store(self, sections: TPersistedSections) -> None: if not sections: return self.path.parent.mkdir(parents=True, exist_ok=True) store.save_object_to_file(self.path, {str(k): v for k, v in sections.items()}, pretty=False) self._logger.debug("Stored persisted sections: %s", ", ".join(str(s) for s in sections))
def _filter(self, sections: TPersistedSections) -> TPersistedSections: now = time.time() for section_name, entry in list(sections.items()): if len(entry) == 2: persisted_until = entry[0] else: persisted_until = entry[1] if now > persisted_until: self._logger.debug( "Persisted section %s is outdated by %d seconds. Skipping it.", section_name, now - persisted_until) del sections[section_name] return sections
def _add_persisted_sections( self, persisted_sections: TPersistedSections, *, logger: logging.Logger, ) -> None: if not persisted_sections: return for section_name, entry in persisted_sections.items(): if len(entry) == 2: continue # Skip entries of "old" format # Don't overwrite sections that have been received from the source with this call if section_name in self.sections: logger.debug("Skipping persisted section %r, live data available", section_name) continue logger.debug("Using persisted section %r", section_name) self._add_cached_section(section_name, *entry)