[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6DSERPC173AFZ33AA72ND4D":3,"skill-same:01M6DSERPC173AFZ33AA72ND4D":59},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":22,"publishedAt":32,"linkOnly":33,"markdownContent":34,"markdownBody":35,"frontMatter":36,"refName":38,"commitSha":39,"skillDirectory":40,"forksCount":41,"repositoryHtmlUrl":42,"repositoryHomepageUrl":6,"ownerHtmlUrl":43,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":44,"install":45,"resources":58},"01M6DSERPC173AFZ33AA72ND4D","content-hash-cache-pattern",null,"Cache expensive file processing results using SHA-256 content hashes — path-independent, auto-invalidating, with service layer separation.","AntifragileTech\u002Fantifragile-claude-code","AntifragileTech","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F174357194?v=4","01M6DQCYMK4CDSQQAN0ZC72NTV","01M6DQCYS9YPW1WKMQ5TJMPQ43",9,"MIT","https:\u002F\u002Fgithub.com\u002FAntifragileTech\u002Fantifragile-claude-code\u002Fblob\u002Fmaster\u002Fassets\u002Fskills\u002Fmarketing\u002Fcontent-hash-cache-pattern\u002FSKILL.md",[17],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000036","内容创作者","PROFESSION","适用职业",[23,24,25,26,27,28,29,30,31],"content","cache","pattern","content hash cache pattern","file","sha-256","results","auto","service","2026-11-10 10:12:30",false,"---\nname: content-hash-cache-pattern\ndescription: Cache expensive file processing results using SHA-256 content hashes — path-independent, auto-invalidating, with service layer separation.\norigin: ECC\n---\n\n# Content-Hash File Cache Pattern\n\nCache expensive file processing results (PDF parsing, text extraction, image analysis) using SHA-256 content hashes as cache keys. Unlike path-based caching, this approach survives file moves\u002Frenames and auto-invalidates when content changes.\n\n## When to Activate\n\n- Building file processing pipelines (PDF, images, text extraction)\n- Processing cost is high and same files are processed repeatedly\n- Need a `--cache\u002F--no-cache` CLI option\n- Want to add caching to existing pure functions without modifying them\n\n## Core Pattern\n\n### 1. Content-Hash Based Cache Key\n\nUse file content (not path) as the cache key:\n\n```python\nimport hashlib\nfrom pathlib import Path\n\n_HASH_CHUNK_SIZE = 65536  # 64KB chunks for large files\n\ndef compute_file_hash(path: Path) -> str:\n    \"\"\"SHA-256 of file contents (chunked for large files).\"\"\"\n    if not path.is_file():\n        raise FileNotFoundError(f\"File not found: {path}\")\n    sha256 = hashlib.sha256()\n    with open(path, \"rb\") as f:\n        while True:\n            chunk = f.read(_HASH_CHUNK_SIZE)\n            if not chunk:\n                break\n            sha256.update(chunk)\n    return sha256.hexdigest()\n```\n\n**Why content hash?** File rename\u002Fmove = cache hit. Content change = automatic invalidation. No index file needed.\n\n### 2. Frozen Dataclass for Cache Entry\n\n```python\nfrom dataclasses import dataclass\n\n@dataclass(frozen=True, slots=True)\nclass CacheEntry:\n    file_hash: str\n    source_path: str\n    document: ExtractedDocument  # The cached result\n```\n\n### 3. File-Based Cache Storage\n\nEach cache entry is stored as `{hash}.json` — O(1) lookup by hash, no index file required.\n\n```python\nimport json\nfrom typing import Any\n\ndef write_cache(cache_dir: Path, entry: CacheEntry) -> None:\n    cache_dir.mkdir(parents=True, exist_ok=True)\n    cache_file = cache_dir \u002F f\"{entry.file_hash}.json\"\n    data = serialize_entry(entry)\n    cache_file.write_text(json.dumps(data, ensure_ascii=False), encoding=\"utf-8\")\n\ndef read_cache(cache_dir: Path, file_hash: str) -> CacheEntry | None:\n    cache_file = cache_dir \u002F f\"{file_hash}.json\"\n    if not cache_file.is_file():\n        return None\n    try:\n        raw = cache_file.read_text(encoding=\"utf-8\")\n        data = json.loads(raw)\n        return deserialize_entry(data)\n    except (json.JSONDecodeError, ValueError, KeyError):\n        return None  # Treat corruption as cache miss\n```\n\n### 4. Service Layer Wrapper (SRP)\n\nKeep the processing function pure. Add caching as a separate service layer.\n\n```python\ndef extract_with_cache(\n    file_path: Path,\n    *,\n    cache_enabled: bool = True,\n    cache_dir: Path = Path(\".cache\"),\n) -> ExtractedDocument:\n    \"\"\"Service layer: cache check -> extraction -> cache write.\"\"\"\n    if not cache_enabled:\n        return extract_text(file_path)  # Pure function, no cache knowledge\n\n    file_hash = compute_file_hash(file_path)\n\n    # Check cache\n    cached = read_cache(cache_dir, file_hash)\n    if cached is not None:\n        logger.info(\"Cache hit: %s (hash=%s)\", file_path.name, file_hash[:12])\n        return cached.document\n\n    # Cache miss -> extract -> store\n    logger.info(\"Cache miss: %s (hash=%s)\", file_path.name, file_hash[:12])\n    doc = extract_text(file_path)\n    entry = CacheEntry(file_hash=file_hash, source_path=str(file_path), document=doc)\n    write_cache(cache_dir, entry)\n    return doc\n```\n\n## Key Design Decisions\n\n| Decision | Rationale |\n|----------|-----------|\n| SHA-256 content hash | Path-independent, auto-invalidates on content change |\n| `{hash}.json` file naming | O(1) lookup, no index file needed |\n| Service layer wrapper | SRP: extraction stays pure, cache is a separate concern |\n| Manual JSON serialization | Full control over frozen dataclass serialization |\n| Corruption returns `None` | Graceful degradation, re-processes on next run |\n| `cache_dir.mkdir(parents=True)` | Lazy directory creation on first write |\n\n## Best Practices\n\n- **Hash content, not paths** — paths change, content identity doesn't\n- **Chunk large files** when hashing — avoid loading entire files into memory\n- **Keep processing functions pure** — they should know nothing about caching\n- **Log cache hit\u002Fmiss** with truncated hashes for debugging\n- **Handle corruption gracefully** — treat invalid cache entries as misses, never crash\n\n## Anti-Patterns to Avoid\n\n```python\n# BAD: Path-based caching (breaks on file move\u002Frename)\ncache = {\"\u002Fpath\u002Fto\u002Ffile.pdf\": result}\n\n# BAD: Adding cache logic inside the processing function (SRP violation)\ndef extract_text(path, *, cache_enabled=False, cache_dir=None):\n    if cache_enabled:  # Now this function has two responsibilities\n        ...\n\n# BAD: Using dataclasses.asdict() with nested frozen dataclasses\n# (can cause issues with complex nested types)\ndata = dataclasses.asdict(entry)  # Use manual serialization instead\n```\n\n## When to Use\n\n- File processing pipelines (PDF parsing, OCR, text extraction, image analysis)\n- CLI tools that benefit from `--cache\u002F--no-cache` options\n- Batch processing where the same files appear across runs\n- Adding caching to existing pure functions without modifying them\n\n## When NOT to Use\n\n- Data that must always be fresh (real-time feeds)\n- Cache entries that would be extremely large (consider streaming instead)\n- Results that depend on parameters beyond file content (e.g., different extraction configs)\n","# Content-Hash File Cache Pattern\n\nCache expensive file processing results (PDF parsing, text extraction, image analysis) using SHA-256 content hashes as cache keys. Unlike path-based caching, this approach survives file moves\u002Frenames and auto-invalidates when content changes.\n\n## When to Activate\n\n- Building file processing pipelines (PDF, images, text extraction)\n- Processing cost is high and same files are processed repeatedly\n- Need a `--cache\u002F--no-cache` CLI option\n- Want to add caching to existing pure functions without modifying them\n\n## Core Pattern\n\n### 1. Content-Hash Based Cache Key\n\nUse file content (not path) as the cache key:\n\n```python\nimport hashlib\nfrom pathlib import Path\n\n_HASH_CHUNK_SIZE = 65536  # 64KB chunks for large files\n\ndef compute_file_hash(path: Path) -> str:\n    \"\"\"SHA-256 of file contents (chunked for large files).\"\"\"\n    if not path.is_file():\n        raise FileNotFoundError(f\"File not found: {path}\")\n    sha256 = hashlib.sha256()\n    with open(path, \"rb\") as f:\n        while True:\n            chunk = f.read(_HASH_CHUNK_SIZE)\n            if not chunk:\n                break\n            sha256.update(chunk)\n    return sha256.hexdigest()\n```\n\n**Why content hash?** File rename\u002Fmove = cache hit. Content change = automatic invalidation. No index file needed.\n\n### 2. Frozen Dataclass for Cache Entry\n\n```python\nfrom dataclasses import dataclass\n\n@dataclass(frozen=True, slots=True)\nclass CacheEntry:\n    file_hash: str\n    source_path: str\n    document: ExtractedDocument  # The cached result\n```\n\n### 3. File-Based Cache Storage\n\nEach cache entry is stored as `{hash}.json` — O(1) lookup by hash, no index file required.\n\n```python\nimport json\nfrom typing import Any\n\ndef write_cache(cache_dir: Path, entry: CacheEntry) -> None:\n    cache_dir.mkdir(parents=True, exist_ok=True)\n    cache_file = cache_dir \u002F f\"{entry.file_hash}.json\"\n    data = serialize_entry(entry)\n    cache_file.write_text(json.dumps(data, ensure_ascii=False), encoding=\"utf-8\")\n\ndef read_cache(cache_dir: Path, file_hash: str) -> CacheEntry | None:\n    cache_file = cache_dir \u002F f\"{file_hash}.json\"\n    if not cache_file.is_file():\n        return None\n    try:\n        raw = cache_file.read_text(encoding=\"utf-8\")\n        data = json.loads(raw)\n        return deserialize_entry(data)\n    except (json.JSONDecodeError, ValueError, KeyError):\n        return None  # Treat corruption as cache miss\n```\n\n### 4. Service Layer Wrapper (SRP)\n\nKeep the processing function pure. Add caching as a separate service layer.\n\n```python\ndef extract_with_cache(\n    file_path: Path,\n    *,\n    cache_enabled: bool = True,\n    cache_dir: Path = Path(\".cache\"),\n) -> ExtractedDocument:\n    \"\"\"Service layer: cache check -> extraction -> cache write.\"\"\"\n    if not cache_enabled:\n        return extract_text(file_path)  # Pure function, no cache knowledge\n\n    file_hash = compute_file_hash(file_path)\n\n    # Check cache\n    cached = read_cache(cache_dir, file_hash)\n    if cached is not None:\n        logger.info(\"Cache hit: %s (hash=%s)\", file_path.name, file_hash[:12])\n        return cached.document\n\n    # Cache miss -> extract -> store\n    logger.info(\"Cache miss: %s (hash=%s)\", file_path.name, file_hash[:12])\n    doc = extract_text(file_path)\n    entry = CacheEntry(file_hash=file_hash, source_path=str(file_path), document=doc)\n    write_cache(cache_dir, entry)\n    return doc\n```\n\n## Key Design Decisions\n\n| Decision | Rationale |\n|----------|-----------|\n| SHA-256 content hash | Path-independent, auto-invalidates on content change |\n| `{hash}.json` file naming | O(1) lookup, no index file needed |\n| Service layer wrapper | SRP: extraction stays pure, cache is a separate concern |\n| Manual JSON serialization | Full control over frozen dataclass serialization |\n| Corruption returns `None` | Graceful degradation, re-processes on next run |\n| `cache_dir.mkdir(parents=True)` | Lazy directory creation on first write |\n\n## Best Practices\n\n- **Hash content, not paths** — paths change, content identity doesn't\n- **Chunk large files** when hashing — avoid loading entire files into memory\n- **Keep processing functions pure** — they should know nothing about caching\n- **Log cache hit\u002Fmiss** with truncated hashes for debugging\n- **Handle corruption gracefully** — treat invalid cache entries as misses, never crash\n\n## Anti-Patterns to Avoid\n\n```python\n# BAD: Path-based caching (breaks on file move\u002Frename)\ncache = {\"\u002Fpath\u002Fto\u002Ffile.pdf\": result}\n\n# BAD: Adding cache logic inside the processing function (SRP violation)\ndef extract_text(path, *, cache_enabled=False, cache_dir=None):\n    if cache_enabled:  # Now this function has two responsibilities\n        ...\n\n# BAD: Using dataclasses.asdict() with nested frozen dataclasses\n# (can cause issues with complex nested types)\ndata = dataclasses.asdict(entry)  # Use manual serialization instead\n```\n\n## When to Use\n\n- File processing pipelines (PDF parsing, OCR, text extraction, image analysis)\n- CLI tools that benefit from `--cache\u002F--no-cache` options\n- Batch processing where the same files appear across runs\n- Adding caching to existing pure functions without modifying them\n\n## When NOT to Use\n\n- Data that must always be fresh (real-time feeds)\n- Cache entries that would be extremely large (consider streaming instead)\n- Results that depend on parameters beyond file content (e.g., different extraction configs)\n",{"name":5,"origin":37,"description":7},"ECC","master","c73386b305dec167db7654e0e6feacb462d4f9dc","assets\u002Fskills\u002Fmarketing\u002Fcontent-hash-cache-pattern",1,"https:\u002F\u002Fgithub.com\u002FAntifragileTech\u002Fantifragile-claude-code","https:\u002F\u002Fgithub.com\u002FAntifragileTech","2026-10-02 14:22:14",{"source":8,"skillName":5,"commands":46,"prompt":56,"zipAvailable":57},[47,50,53],{"tool":48,"command":49},"npx","npx skills add AntifragileTech\u002Fantifragile-claude-code --skill content-hash-cache-pattern",{"tool":51,"command":52},"bunx","bunx skills add AntifragileTech\u002Fantifragile-claude-code --skill content-hash-cache-pattern",{"tool":54,"command":55},"pnpm","pnpm dlx skills add AntifragileTech\u002Fantifragile-claude-code --skill content-hash-cache-pattern","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FAntifragileTech\u002Fantifragile-claude-code\u002Fblob\u002Fmaster\u002Fassets\u002Fskills\u002Fmarketing\u002Fcontent-hash-cache-pattern\u002FSKILL.md",true,[],[60,82,97,112,125,138],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":75,"publishedAt":32},"01M6DT9Q6VYA615SCXR757TZZ7","writing-skills","Use when creating new skills, editing existing skills, or verifying skills work before deployment","https:\u002F\u002Fgithub.com\u002FAntifragileTech\u002Fantifragile-claude-code\u002Fblob\u002Fmaster\u002Fassets\u002Fskills\u002Fthinking\u002Fwriting-skills\u002FSKILL.md",[66,71,74],{"categoryNo":67,"categoryName":68,"taxonomyType":69,"taxonomyTypeDesc":70},"01JBSEEDCAT000000000000008","测试与质量","SCENARIO","使用场景",{"categoryNo":72,"categoryName":73,"taxonomyType":69,"taxonomyTypeDesc":70},"01JBSEEDCAT000000000000018","写作与文案",{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},[76,77,78,79,80,81],"writing skills","writing","use","editing","work","deployment",{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":90,"publishedAt":32},"01M6DT9GFHDNY90P41WGAE1TV0","writing-plans","Use when you have a spec or requirements for a multi-step task, before touching code","https:\u002F\u002Fgithub.com\u002FAntifragileTech\u002Fantifragile-claude-code\u002Fblob\u002Fmaster\u002Fassets\u002Fskills\u002Fthinking\u002Fwriting-plans\u002FSKILL.md",[88,89],{"categoryNo":72,"categoryName":73,"taxonomyType":69,"taxonomyTypeDesc":70},{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},[91,92,77,93,94,78,95,96],"plans","writing plans","requirements","task","code","spec",{"skillNo":98,"name":99,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":105,"publishedAt":32},"01M6DT9C6PFGD86WS3HY7YE3XG","docs:write-concisely","Apply writing rules to any documentation that humans will read. Makes your writing clearer, stronger, and more professional.","https:\u002F\u002Fgithub.com\u002FAntifragileTech\u002Fantifragile-claude-code\u002Fblob\u002Fmaster\u002Fassets\u002Fskills\u002Fthinking\u002Fwrite-concisely\u002FSKILL.md",[103,104],{"categoryNo":72,"categoryName":73,"taxonomyType":69,"taxonomyTypeDesc":70},{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},[106,107,108,109,110,111,77],"docs:write concisely","write","docs","read","Rules","documentation",{"skillNo":113,"name":114,"nameZh":6,"description":115,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":116,"categories":117,"keywords":118,"publishedAt":32},"01M6DT98AWQ27P0N1CG97WAG66","kaizen:why","Iterative Five Whys root cause analysis drilling from symptoms to fundamentals","https:\u002F\u002Fgithub.com\u002FAntifragileTech\u002Fantifragile-claude-code\u002Fblob\u002Fmaster\u002Fassets\u002Fskills\u002Fthinking\u002Fwhy\u002FSKILL.md",[],[114,119,120,121,122,123,124],"why","kaizen","issue","five whys","analysis","root cause analysis",{"skillNo":126,"name":127,"nameZh":6,"description":128,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":129,"categories":130,"keywords":131,"publishedAt":32},"01M6DT93EH25NAX19R3WGE1P53","verification-loop","A comprehensive verification system for Claude Code sessions.","https:\u002F\u002Fgithub.com\u002FAntifragileTech\u002Fantifragile-claude-code\u002Fblob\u002Fmaster\u002Fassets\u002Fskills\u002Fthinking\u002Fverification-loop\u002FSKILL.md",[],[132,133,134,135,95,136,137],"verification loop","verification","loop","sessions","claude code sessions","system",{"skillNo":139,"name":140,"nameZh":6,"description":141,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":142,"categories":143,"keywords":144,"publishedAt":32},"01M6DT90GW7Z7VCN98P9DVYSNC","verification-before-completion","Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always","https:\u002F\u002Fgithub.com\u002FAntifragileTech\u002Fantifragile-claude-code\u002Fblob\u002Fmaster\u002Fassets\u002Fskills\u002Fthinking\u002Fverification-before-completion\u002FSKILL.md",[],[145,133,146,80,78,147,148,149],"verification before completion","commands","evidence","claim","complete"]