def get(self, key): c = self.connection.cursor() c.execute( f""" SELECT metadata, state_data FROM {self.table} WHERE query=? """, [key], ) try: metadata, data = c.fetchone() metadata = json.loads(metadata) if metadata.get("status") != "ready": return None except: return None try: state = State() state = state.from_dict(metadata) t = state_types_registry().get(state.type_identifier) state.data = t.from_bytes(self.decode(data)) return state except: logging.exception(f"Cache failed to recover {key}") return None
def get(self, key): state_path = self.to_path(key) if os.path.exists(state_path): state = State() state = state.from_dict(json.loads(open(state_path).read())) else: return None t = state_types_registry().get(state.type_identifier) path = self.to_path(key, prefix="data_", extension=t.default_extension()) if os.path.exists(path): try: state.data = t.from_bytes(open(path, "rb").read()) return state except: logging.exception(f"Cache failed to recover {key}") return None
def get(self, key): metadata = self.get_metadata(key) if metadata is None: print(f"(FileCache) Metadata missing: {key}") return None if metadata.get("status") != "ready": print(f"(FileCache) Not ready {key}; ", metadata.get("status")) return None state = State() state.metadata = metadata t = state_types_registry().get(metadata["type_identifier"]) path = self.to_path(key, prefix="data_", extension=t.default_extension()) if os.path.exists(path): try: state.data = t.from_bytes(self.decode(open(path, "rb").read())) return state except: traceback.print_exc() logging.exception(f"Cache failed to recover {key}") return None
def get(self, key): print(f"GET {key}") metadata = self.get_metadata(key) print(f" METADATA {metadata}") if metadata is None: print(f"(StoreCache) Metadata missing: {key}") return None if metadata.get("status") != "ready": print(f"(StoreCache) Not ready {key}; ", metadata.get("status")) return None state = State() state.metadata = metadata t = state_types_registry().get(metadata["type_identifier"]) path = self.to_path(key) if self.storage.contains(path): try: state.data = t.from_bytes(self.decode(self.storage.get_bytes(path))) return state except: traceback.print_exc() logging.exception(f"Cache failed to recover {key}") return None