Example #1
0
    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
Example #2
0
    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