content-hash-cache-pattern

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

Updated May 27, 2025
One-click install
npx skills add https://github.com/vinwang/tools --skill content-hash-cache-pattern-vinwang
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: content-hash-cache-pattern
Source: https://github.com/vinwang/tools/tree/main/iflow/skills/content-hash-cache-pattern
Command: npx skills add https://github.com/vinwang/tools --skill content-hash-cache-pattern-vinwang

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Cache expensive file processing results using SHA-256 content hashes as cache keys. This approach is path-independent and auto-invalidates when content changes, with a service layer to separate concerns.

Core Features & Use Cases

  • Content-hash based cache key using file contents (not paths) to ensure cache validity across moves or renames.
  • Frozen dataclass for cache entries to guarantee immutability and consistent serialization.
  • File-based cache storage with {hash}.json entries for O(1) lookups.
  • Service layer wrapper that keeps processing pure and delegates caching to a separate concern.
  • Works in pipelines for PDFs, OCR, and image analysis to accelerate repeated processing.

Quick Start

Process a file by running the cache-enabled pipeline to retrieve a cached result when possible, or compute and store a new result otherwise.

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 so they stay valid after renaming or moving files?

You can cache file processing results by using SHA-256 content hashes as cache keys. This makes caching path-independent and auto-invalidates when file content changes, allowing cache reuse across moves and renames.

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

The best way to auto-invalidate cached data is using a content-hash based cache key. By hashing file contents with SHA-256, the cache automatically invalidates when the content changes, without relying on file paths.

How do I implement a content-hash cache for expensive file processing pipelines like OCR and PDF analysis?

Implement a content-hash cache by computing a SHA-256 hash for input files, storing results in file-based {hash}.json entries for O(1) lookups. A service-layer wrapper keeps processing pure while delegating caching to a separate concern.

Does content-hash caching work without external dependencies for storing processed file results?

Yes, content-hash caching works without external dependencies by using file-based cache storage. It stores results as {hash}.json entries and uses a frozen dataclass for cache entries to guarantee immutability and consistent serialization.

Why use a service layer wrapper when implementing a file caching pattern?

You use a service layer wrapper to separate concerns, keeping the file processing logic pure while delegating caching to a separate component. This ensures the processing pipeline remains clean and the cache logic is independently managed.

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

You should not use a content-hash approach when the caching overhead of computing SHA-256 hashes outweighs the cost of the file processing itself, or when dealing with strictly path-dependent workflows where content stability is guaranteed.