
Content Hash Cache Pattern
Caches expensive file operations like PDF parsing or image analysis by hashing file content with SHA-256 instead of tracking paths. The smart bit is that renamed files still hit the cache, and edited files automatically invalidate. It wraps your processing functions in a service layer so they stay pure and cache-unaware, stores results as individual JSON files keyed by hash, and handles the typical edge cases like corruption and missing directories. Works well for CLI tools that reprocess the same files across runs. Skip it if you need parameters beyond file content to determine the result, or if your cache entries would be massive.
- skills.sh installs
- 5.4K
- GitHub stars
- 300.3K
- last updated
- Aug 21, 2026
Install
$ npx -y skills add affaan-m/ecc --skill content-hash-cache-pattern --agent claude-codeInstalls into .claude/skills of the current project.
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-cacheCLI 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()
Sponsors
Details
- Repository
- github.com/affaan-m/ecc
- First seen
- Jul 14, 2026
More from affaan-m/ecc
All 263- Network Config Validation5.4K
- Dmux Workflows5.4K
- Quarkus Patterns5.4K
- Ecc Tools Cost Audit5.4K
- Foundation Models On Device5.4K
- Network Interface Health5.4K
- Netmiko Ssh Automation5.4K
- Swift Concurrency 6 25.4K
- Opensource Pipeline5.4K
- Plankton Code Quality5.4K
- Defi Amm Security5.4K
- Gan Style Harness5.4K
- Homelab Pihole Dns5.4K
- Returns Reverse Logistics5.4K
- Benchmark Optimization Loop5.4K
- Customer Billing Ops5.4K
- Openclaw Persona Forge5.4K
- Google Workspace Ops5.4K
- Hookify Rules5.4K
- Connections Optimizer5.4K
- Swift Protocol Di Testing5.4K
- Energy Procurement5.4K
- Swift Actor Persistence5.4K
- Quarkus Security5.4K