Skip to content
affaan-m avatar

Content Hash Cache Pattern

Caches expensive file-processing results keyed by SHA-256 content hash rather than file path.

CCM score
77 of 100
skills.sh installs
12.1K
GitHub stars
312.6K
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers a service-layer pattern for caching PDF parsing, text extraction, and image analysis results
  • Includes compute_file_hash, a frozen CacheEntry dataclass, and {hash}.json storage with corruption handled as a miss
  • Enforces separation of concerns so processing functions stay pure and know nothing about caching
  • Designed for batch pipelines and CLI tools with --cache/--no-cache options, not real-time or parameter-dependent results

Install

$ npx -y skills add affaan-m/ecc --skill content-hash-cache-pattern -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Content-Hash File Cache Pattern

Cache 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/renames and auto-invalidates when content changes.

When to Activate

  • Building file processing pipelines (PDF, images, text extraction)
  • Processing cost is high and same files are processed repeatedly
  • Need a --cache/--no-cache CLI option
  • Want to add caching to existing pure functions without modifying them

Core Pattern

1. Content-Hash Based Cache Key

Use file content (not path) as the cache key:

import hashlib
from pathlib import Path

_HASH_CHUNK_SIZE = 65536  # 64KB chunks for large files

def compute_file_hash(path: Path) -> str:
    """SHA-256 of file contents (chunked for large files)."""
    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()

Details

Repository
github.com/affaan-m/ecc
Category
Python
First seen
Jul 14, 2026

Questions

What does the content-hash-cache-pattern skill do?

It caches expensive file processing results such as PDF parsing, text extraction and image analysis, using SHA-256 hashes of file contents as cache keys. Because the key is the content rather than the path, cached results survive file moves and renames and invalidate automatically when content changes.

How do I install the content-hash-cache-pattern skill?

Run npx -y skills add affaan-m/ecc --skill content-hash-cache-pattern -y in your project. This lets the agent apply the hash-based caching pattern when you build file processing pipelines.

Where does content-hash-cache-pattern rank among Python skills?

It ranks in the top 25 on the Python category page of Claude Marketplaces. Other skills in that category include python-performance-optimization, python-design-patterns, async-python-patterns, python-code-style and uv-package-manager.

When should I use this caching skill instead of path-based caching?

Use it when repeated file processing is slow and the same files reappear across runs, or when you want a --cache/--no-cache CLI option. It keeps the processing function pure by wrapping it in a service layer, and it is not suited to data that must always be fresh.

More from affaan-m/ecc

All 257

Similar to Content Hash Cache Pattern

More Python