Install any skill in seconds. Free to start, no credit card required.
Get Started Free →xu-xiang/content-hash-cache-pattern
使用 SHA-256 内容哈希缓存高昂的文件处理结果 —— 与路径无关、自动失效且服务层分离。
Passed 22 of 22 test cases with the skill, and 18 of 22 without it.
and 2 more in the full report
4 fixed18 passed either way0 still failing0 broke
Tokens, turns and time describe resource use, not a dollar price.
One of 4 test cases the skill fixed. Same model, same prompt, with and without the skill.
When logging cache hits and misses during batch file processing runs, what format should be used for printing the content hash in log messages?
| Checked | Without skill | With skill |
|---|---|---|
| Logs a truncated prefix of the SHA-256 hash string rather than the full hex string. | Missed | Passed |
The instructions your model reads when the skill loads.
使用 SHA-256 内容哈希(而非文件路径)作为缓存键,缓存高昂的文件处理结果(如 PDF 解析、文本提取、图像分析)。与基于路径的缓存不同,这种方法在文件移动/重命名后依然有效,并在内容变化时自动失效。
--cache/--no-cache 命令行选项使用文件内容(而非路径)作为缓存键:
import hashlib
from pathlib import Path
_HASH_CHUNK_SIZE = 65536 # 大文件采用 64KB 分块读取
def compute_file_hash(path: Path) -> str:
"""计算文件内容的 SHA-256 哈希值(针对大文件进行分块)。"""
if not path.is_file():
raise FileNotFoundError(f"File not found: {path}")
sha256 = hashlib.sha256()
with open(path, "rb") as f:
while True:
chunk = f.read(_HASH_CHUNK_SIZE)
if not chunk:
break
sha256.update(chunk)
return sha256.hexdigest()
为什么使用内容哈希? 文件重命名/移动 = 缓存命中。内容更改 = 自动失效。无需索引文件。
test cases passed, vs 18 / 22 without
Published skills whose descriptions closely match this one, with their headline benchmark lift.
More skills from the same source and nearby in the registry, with their headline benchmark lift.