| 73 | return cached_path, cached_path_lock, sub_path |
| 74 | |
| 75 | def get(self, inputs_hash, lock_retries=2) -> dict | None: # output_obj |
| 76 | cached_path, cached_path_lock, _ = self.hash_paths(inputs_hash) |
| 77 | if not cached_path_lock.exists(): |
| 78 | for retry in range(lock_retries): |
| 79 | try: |
| 80 | with open(cached_path, "rb") as fp: |
| 81 | logger.debug( |
| 82 | "Loading cache hit: %s (try %d/%d)", |
| 83 | cached_path, |
| 84 | retry, |
| 85 | lock_retries, |
| 86 | ) |
| 87 | output_obj = self.load_output(fp) |
| 88 | # load_output can return None when a kadet |
| 89 | # ModuleNotFoundError is swallowed; treat that as a |
| 90 | # miss so the caller recomputes. |
| 91 | if output_obj is None: |
| 92 | self.metrics.miss() |
| 93 | else: |
| 94 | self.metrics.hit() |
| 95 | return output_obj |
| 96 | except FileNotFoundError: |
| 97 | pass |
| 98 | self.metrics.miss() |
| 99 | return None |
| 100 | |
| 101 | def set(self, inputs_hash, output_obj, lock_retries=2): |
| 102 | cached_path, cached_path_lock, sub_path = self.hash_paths(inputs_hash) |