content-hash-cache-pattern

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

2|Updated Apr 5, 2026
One-click install
npx skills add https://github.com/mbadoz/mbadoz-skills --skill content-hash-cache-pattern-mbadoz
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: content-hash-cache-pattern
Source: https://github.com/mbadoz/mbadoz-skills/tree/main/plugins/built-planner/skills/built-planner/references/skills/content-hash-cache-pattern
Command: npx skills add https://github.com/mbadoz/mbadoz-skills --skill content-hash-cache-pattern-mbadoz

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Cache expensive file processing results using SHA-256 content hashes as cache keys. Path-based caching fails when files are renamed or moved, so content identity becomes the stable key and changes invalidate the cache automatically.

Core Features & Use Cases

  • Content-hash based cache keys for file processing (PDFs, images, text, and other large files) to survive moves and renames.
  • A separate service layer keeps the processing function pure while caching is handled as a separate concern.
  • File-based cache storage stores each entry as a JSON file named by the content hash, with lazy directory creation and corruption-tolerant reads.

Quick Start

Run a workflow that computes a file's content hash and retrieves a cached result if available; otherwise, process the file and write the new result to the 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 file processing results when files get renamed or moved?

Cache file processing results using SHA-256 content hashes as cache keys instead of file paths. Content identity remains stable across moves and renames, automatically invalidating the cache only when the file's actual data changes.

What is the best way to avoid reprocessing large PDFs and images in Python?

Use a content-hash caching pattern to avoid reprocessing large PDFs and images. A wrapper service checks a JSON cache store keyed by SHA-256 hash, returning cached results on hits and invoking your pure extractor function only on misses.

How does content-hash caching keep the file processing function pure?

Content-hash caching keeps the processing function pure by separating concerns. A dedicated wrapper service manages cache hits, misses, and JSON storage, while your extractor function solely processes file data without handling cache logic.

How does the file-based cache handle storage and corrupted cache files?

The file-based cache stores each entry as a JSON file named by the content hash, featuring lazy directory creation. It performs corruption-tolerant reads to gracefully handle and bypass corrupted cache files without crashing the workflow.

Do I need a specific caching service or database to use this content-hash pattern?

No specific database is required; the pattern uses a configurable cache directory for file-based storage. You only need a pure extractor function and the wrapper service to manage the JSON cache store using a local directory.