Look up cached IWYU result for a file. Args: file_path: Source file path. compiler_args_key: Compiler args fingerprint. Returns: List of removal strings if cached (empty list = clean), or None on cache miss.
(self, file_path: Path, compiler_args_key: str)
| 125 | pass # Non-fatal |
| 126 | |
| 127 | def get(self, file_path: Path, compiler_args_key: str) -> list[str] | None: |
| 128 | """Look up cached IWYU result for a file. |
| 129 | |
| 130 | Args: |
| 131 | file_path: Source file path. |
| 132 | compiler_args_key: Compiler args fingerprint. |
| 133 | |
| 134 | Returns: |
| 135 | List of removal strings if cached (empty list = clean), |
| 136 | or None on cache miss. |
| 137 | """ |
| 138 | if not self._enabled: |
| 139 | self._misses += 1 |
| 140 | return None |
| 141 | |
| 142 | file_hash = _compute_file_hash( |
| 143 | file_path, compiler_args_key, self._source_tree_hash |
| 144 | ) |
| 145 | key = str(file_path) |
| 146 | |
| 147 | entry = self._data.get(key) |
| 148 | if entry is not None and entry.get("hash") == file_hash: |
| 149 | removals = entry.get("removals") |
| 150 | if isinstance(removals, list): |
| 151 | self._hits += 1 |
| 152 | return removals |
| 153 | |
| 154 | self._misses += 1 |
| 155 | return None |
| 156 | |
| 157 | def put(self, file_path: Path, compiler_args_key: str, removals: list[str]) -> None: |
| 158 | """Store IWYU result for a file. |