content-hash-cache-pattern

Cache file processing results using SHA-256 content hashes as keys.

Updated Mar 16, 2026
One-click install
npx skills add https://github.com/thmspi/claude-setup --skill content-hash-cache-pattern-thmspi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: content-hash-cache-pattern
Source: https://github.com/thmspi/claude-setup/tree/main/.claude/skills/content-hash-cache-pattern
Command: npx skills add https://github.com/thmspi/claude-setup --skill content-hash-cache-pattern-thmspi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Cache expensive file processing results using SHA-256 content hashes as cache keys. Unlike path-based caching, this approach survives file moves/renames and auto-invalidates when content changes.

Core Features & Use Cases

  • Content-hash Based Cache Key: uses file content hash as the cache key, making caches robust to file renames and moves.
  • Frozen Dataclass for Cache Entry: defines an immutable, efficient cache entry structure.
  • File-Based Cache Storage: stores each entry as a {hash}.json for O(1) lookups without an index.
  • Service Layer Wrapper (SRP): separates the cache logic from the processing function, keeping processing pure.

Quick Start

Enable the content-hash cache in your file-processing pipeline to automatically cache results based on file content.

Frequently Asked Questions about content-hash-cache-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I cache file processing results so they survive renames and moves?

Use SHA-256 content hashing to cache file processing results, which creates cache keys based on file content rather than file paths. This ensures your cache remains valid and survives file renames or moves without invalidation.

What's the best way to prevent recomputing expensive file processing pipelines for large documents?

Implement a content-hash cache using SHA-256 to store file processing results as JSON files. This prevents recomputation by checking the content hash before processing, providing O(1) lookups without needing a separate index for your large documents.

Why does path-based caching break when processing PDFs and images?

Path-based caching breaks because it relies on file location rather than content identity. Content-hash caching solves this by using SHA-256 hashes as keys, automatically invalidating when file content changes and remaining robust against file renames and moves.

How do I handle cache misses and corrupted cache files in a file processing pipeline?

Handle cache misses and corruption gracefully by implementing a file-based JSON cache storage system that separates cache logic from the processing function. This pure service layer wrapper automatically detects corruption and reprocesses files when needed.

Does content-hash caching require a database for storing cached file processing results?

No, content-hash caching uses file-based JSON cache storage where each entry is stored as a {hash}.json file. This approach provides O(1) lookups without requiring a database or an index, keeping the cache storage lightweight and portable.

Can I use a content-hash cache with a pure processing function without coupling cache logic?

Yes, the service layer wrapper follows the Single Responsibility Principle by separating cache logic from the processing function. This keeps your processing function pure while the caching service handles SHA-256 hashing, storage, and cache retrieval independently.