content-hash-cache-pattern

Cache file processing results using SHA-256 content hashes.

Updated Apr 2, 2026
One-click install
npx skills add https://github.com/richardnpaul/everything-vscode-copilot --skill content-hash-cache-pattern-richardnpaul
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: content-hash-cache-pattern
Source: https://github.com/richardnpaul/everything-vscode-copilot/tree/main/.github/skills/content-hash-cache-pattern
Command: npx skills add https://github.com/richardnpaul/everything-vscode-copilot --skill content-hash-cache-pattern-richardnpaul

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Cache expensive file processing results using SHA-256 content hashes as cache keys, making caches path-independent and auto-invalidating on content changes, with a clear separation between the processing logic and caching.

Core Features & Use Cases

  • Content-Hash Based Cache Key: uses file contents (not paths) to compute a hash for cache lookups, so moves or renames do not invalidate valid hits.
  • Frozen Dataclass for Cache Entry and File-Based Storage: stores entries as {hash}.json for O(1) lookups and deterministic deserialization.
  • Service Layer Wrapper: keeps the extraction/processing function pure and applies caching as a separate concern, enabling easy testing and predictable behavior.
  • Lazy Cache Directory Creation: creates the cache directory only when writing, avoiding unnecessary filesystem churn.

Quick Start

Run a target file through the cache-enabled processor to observe cache hits on repeat processing and misses on changes.

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 don't recompute on repeated runs?

To cache file processing results effectively, compute a SHA-256 content hash of the file to use as the cache key, storing outputs as {hash}.json. This ensures fast reuse on repeated runs by matching file contents rather than file paths.

Why does my file cache miss when I move files to a new directory path?

Path-based file cache keys miss on directory changes because they rely on the file location. A content-hash cache key uses SHA-256 hashing instead, making your cache completely path-independent so moving or renaming files never invalidates valid cache hits.

How do I auto-invalidate cached data when a file's content changes?

To auto-invalidate cached data on content changes, use a SHA-256 content hash as the cache key. When the file content changes, the generated hash changes, automatically bypassing the old cache and forcing a fresh processing run for the updated file.

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

The best way to cache PDF text extraction and image analysis results is using a separate service layer to coordinate SHA-256 content hashing and {hash}.json storage, keeping the actual processing functions pure and separating caching as a distinct concern.

Does lazy cache directory creation help reduce filesystem churn for large datasets?

Lazy cache directory creation reduces filesystem churn for large datasets by creating the cache directory only when writing a new cache entry. This avoids unnecessary filesystem operations when processing large batches of files that result in cache hits.

How do I keep file processing functions pure while adding a caching layer?

To keep file processing functions pure while adding a caching layer, use a service layer wrapper to coordinate cache lookups, SHA-256 hashing, and {hash}.json storage. This isolates caching as a separate concern, enabling easy testing and predictable behavior.