content-hash-cache-pattern

Caches file processing results using SHA-256 content hashes in {hash}.json files.

2|2|Updated Mar 12, 2026
One-click install
npx skills add https://github.com/zhmxiaowo/opencode-simple --skill content-hash-cache-pattern-zhmxiaowo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: content-hash-cache-pattern
Source: https://github.com/zhmxiaowo/opencode-simple/tree/main/.opencode/skills/content-hash-cache-pattern
Command: npx skills add https://github.com/zhmxiaowo/opencode-simple --skill content-hash-cache-pattern-zhmxiaowo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Cache expensive file processing results using SHA-256 content hashes as cache keys. Path-independence ensures caches survive moves and renames; automatic invalidation occurs when content changes.

Core Features & Use Cases

  • Content-hash based cache key: uses file content, not path, so cache entries remain valid across moves/renames.
  • File-based cache storage: stores entries as {hash}.json for direct O(1) lookups without an index.
  • Service-layer wrapper: keeps processing functions pure while caching is implemented as a separate concern.
  • Use Case: PDF parsing, OCR, or image analysis pipelines where the same file is processed repeatedly.

Quick Start

Wrap your file-processing function with the extract_with_cache service and call it on a path to enable automatic caching.

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 recomputation across runs?

Cache expensive file processing results by computing a SHA-256 content hash for each file and storing outputs as {hash}.json. This content-hash caching pattern eliminates wasted recomputation across runs for identical files.

Why does my file processing cache break when files are moved or renamed?

Path-based cache keys break on file moves or renames. Content-hash caching uses SHA-256 file content as the cache key instead of the file path, ensuring cache entries remain valid and survive directory changes automatically.

How does content hashing handle cache invalidation for changed files?

Content hashing provides automatic cache invalidation because the SHA-256 hash is derived from the file's content. When a file's content changes, its hash changes, bypassing the old cache entry and triggering fresh processing automatically.

What is the best way to cache PDF parsing and text extraction results?

The best way to cache PDF parsing and text extraction results is using a service-layer wrapper around your processing function. This keeps processing logic pure while storing cached outputs as {hash}.json for direct O(1) lookups without an index.

Can I use file-based storage for caching image analysis pipelines without a database?

Yes, you can use file-based storage for caching image analysis pipelines. This pattern stores cache entries as individual {hash}.json files, enabling direct O(1) lookups without requiring a database or external index.

When should I not use a content-hash caching pattern for file processing?

Avoid content-hash caching when file processing is inexpensive or when files are processed only once. Computing SHA-256 hashes adds overhead, so this pattern is best suited for cost-heavy pipelines like OCR where the same files are processed repeatedly.