content-hash-cache-pattern

Cache file processing results using SHA-256 content hashes and JSON files.

1|Updated Mar 18, 2026
One-click install
npx skills add https://github.com/xxih/ai-harness-zh --skill content-hash-cache-pattern-xxih
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: content-hash-cache-pattern
Source: https://github.com/xxih/ai-harness-zh/tree/main/references/translations/everything-claude-code/docs/zh-CN/skills/content-hash-cache-pattern
Command: npx skills add https://github.com/xxih/ai-harness-zh --skill content-hash-cache-pattern-xxih

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Repeatedly processing large files such as PDFs, images, or text extracts can be costly and wasteful when the same content is encountered multiple times. This Skill eliminates redundant work by caching results based on the file’s actual content rather than its path.

Core Features & Use Cases

  • Content‑based cache key: Generates a SHA‑256 hash of the file contents, ensuring cache hits even after the file is moved or renamed.
  • JSON‑serialized cache entries: Stores each result in a {hash}.json file for O(1) lookup and easy corruption handling.
  • Service‑layer wrapper: Keeps the original extraction function pure while adding transparent cache checks and updates.
  • Use case example: In a batch OCR pipeline, enable --cache to avoid re‑reading and processing the same scanned document across multiple runs.

Quick Start

Use the content‑hash cache skill to extract text from 'report.pdf' with caching enabled.

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 expensive file processing results to avoid redundant work in Python?

You can cache expensive file processing results by generating a SHA-256 content hash of your files and storing the processed output as a {hash}.json file in a cache directory. This ensures O(1) lookup and prevents redundant work across multiple pipeline runs.

Why does my file cache miss when a file is moved or renamed?

File caches often miss on rename because they use file paths as keys. Content-hash caching generates a SHA-256 hash from the actual file bytes, ensuring cache hits even after a file is moved or renamed within your pipeline.

What is the best way to cache PDF and image text extraction across multiple batch runs?

The best way to cache PDF and image text extraction is to use a content-hash key based on the file's SHA-256 hash. Results are serialized as JSON files, allowing subsequent batch runs to skip already processed documents instantly.

How does SHA-256 content hashing work for caching JSON serialized file data?

SHA-256 content hashing for JSON caching works by reading the file's bytes to compute a unique hash string. This hash becomes the filename for a JSON file containing the extracted data, providing a reliable and corruption-resistant cache key.

Can I use a content-hash cache pattern with a pure extraction function without modifying the original logic?

Yes, you can apply a service-layer wrapper around your pure extraction function. This wrapper transparently intercepts calls to check the content-hash cache before processing and updates it with new JSON entries only when needed.

Are there limitations to using content-hash caching for large file processing pipelines?

A limitation of content-hash caching is that it requires reading the entire file to compute the SHA-256 hash before checking the cache. For extremely large files, this initial hashing step still incurs I/O costs even when a cache hit occurs.