content-hash-cache-pattern

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Cache expensive file processing results using SHA-256 content hashes as cache keys, enabling path-independence and automatic invalidation when content changes.

Core Features & Use Cases

  • Content-hash based cache keys decouple identity from file paths, so caches survive moves and renames.
  • Deterministic, portable cache entries using a frozen-like CacheEntry structure {file_hash, source_path, document}.
  • File-based storage of cache entries as {hash}.json for O(1) lookups and simple maintenance.
  • Separate service layer wraps the processing function to keep pure logic and separate caching concerns.

Quick Start

Enable caching by wrapping your file-processing function with the cache service and specify a cache directory.

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 in Python so they survive renames or moves?

Cache file processing results using SHA-256 content hashes as cache keys. This decouples cache identity from file paths, ensuring cached data automatically survives file moves or renames across processing runs.

When do I need content-hash based caching for file processing pipelines?

You need content-hash based caching when processing recurring PDF, image, or text files. It automatically invalidates caches when file content changes, skipping expensive reprocessing for identical inputs across pipeline runs.

How do I set up a file-based cache for expensive document processing in Python?

Set up a file-based cache by wrapping your processing function with a cache service layer. It stores results as {hash}.json files in a specified cache directory, enabling O(1) lookups and simple maintenance.

Does this content-hash caching approach work with PDF, image, and text processing tasks?

Yes, content-hash caching works with PDF, image, and text processing tasks. It is applicable to any file processing pipeline where inputs recur across runs and processing costs are expensive.

What's the best way to invalidate a file cache when the source document changes?

Using SHA-256 content hashing is the best way to invalidate caches when source documents change. The hash changes automatically when file content is modified, preventing stale cache lookups without manual path tracking.

Why keep core file processing logic separate from the caching layer?

Keeping core file processing logic separate from caching concerns maintains pure processing functions. A dedicated service layer wraps the processing function to handle caching, ensuring better testability and maintainability.