content-hash-cache-pattern

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Cache expensive file processing results (PDF parsing, text extraction, image analysis) by using SHA-256 content hashes as cache keys. This approach is path independent and auto-invalidates when file content changes, enabling stable reuse across moves and renames.

Core Features & Use Cases

  • Content-hash based cache keys to decouple from file paths
  • Separation of concerns via a service layer that wraps pure processing functions
  • Applies to file-processing pipelines (PDF, images, text extraction) where repeated work can be avoided across runs

Quick Start

Use this pattern to wrap your existing extract_text(...) function with extract_with_cache(...).

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 PDF text extraction results across multiple runs?

Cache expensive PDF text extraction results by using SHA-256 content hashes as cache keys. This approach stores file processing outputs in a frozen CacheEntry dataclass, enabling stable reuse across runs without re-parsing unchanged files.

What is a content-hash cache key and how does it work for file processing?

A content-hash cache key is a SHA-256 hash generated from file contents to store and retrieve processed results. It decouples caching from file paths, ensuring cache validity persists across file moves and renames while auto-invalidating on content changes.

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

Path-based cache keys break on file moves because the path changes. Using SHA-256 content hashes as cache keys provides path independence, allowing your PDF and text extraction caches to survive renames and automatically invalidate only when content changes.

What's the best way to auto-invalidate cached file extraction data when content changes?

Auto-invalidate cached file extraction data by switching to content-hash keys derived from SHA-256. When a file's content changes, its hash changes, naturally bypassing the old cache entry and triggering fresh processing without manual cleanup.

Can I use a service layer to wrap existing file processing functions for caching?

Yes, you can wrap existing pure processing functions like extract_text with a service-layer wrapper such as extract_with_cache. This separation of concerns applies content-hash caching to PDF, image, and text extraction pipelines without modifying core processing logic.