content-hash-cache-pattern

Cache expensive file processing results using SHA-256 content hashes.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Caching expensive file processing results by content hash rather than file path ensures cache validity across moves, renames, and content changes.

Core Features & Use Cases

  • Content-hash based cache key using SHA-256 to uniquely identify file contents.
  • Frozen dataclass (immutable CacheEntry) to guarantee cache entry integrity.
  • Service-layer wrapper to keep core processing pure while handling caching concerns.
  • Graceful handling of corrupted cache entries with safe fallback.

Quick Start

Implement a content-hash cache wrapper around the expensive file-processing function and verify a cache hit on a sample file.

Frequently Asked Questions about content-hash-cache-pattern

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

FAQPage Schema
Why use a content hash instead of a file path for cache keys in file processing pipelines?

Caching by content hash ensures cache validity across file moves, renames, and content changes. Keying on SHA-256 uniquely identifies the file contents rather than its location, preventing stale cache hits.

How do I cache PDF parsing or text extraction results without hitting stale cache entries?

Wrap your expensive file processing function in a service-layer cache keyed by SHA-256 content hash. This keeps core processing logic pure while handling caching concerns, ensuring cache hits across file moves and content changes.

What is the best way to handle corrupted cache entries during JSON serialization?

Implement robust JSON serialization with a frozen dataclass for cache entries, ensuring immutability and integrity. The pattern includes graceful handling of corrupted cache entries with a safe fallback to reprocessing.

Does this content-hash caching pattern work for image processing pipelines as well as text extraction?

Yes, the content-hash caching pattern applies to any expensive file-processing pipeline, including image processing, PDF parsing, and text extraction. It uses SHA-256 to identify file contents uniquely across moves and changes.

How do I maintain Single Responsibility Principle when adding caching to file processing logic?

Use a service-layer wrapper to separate caching concerns from core processing logic. This wrapper handles the content-hash cache lookups and storage, keeping the underlying file processing function pure and focused on its primary task.