content-hash-cache-pattern

Implements file processing caches keyed by SHA-256 content hashes in Python.

1|Updated Oct 11, 2025
One-click install
npx skills add https://github.com/ibytechaos/claude --skill content-hash-cache-pattern-ibytechaos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: content-hash-cache-pattern
Source: https://github.com/ibytechaos/claude/tree/main/plugins/everything-claude-code/skills/content-hash-cache-pattern
Command: npx skills add https://github.com/ibytechaos/claude --skill content-hash-cache-pattern-ibytechaos

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Re-processing expensive files (PDF parsing, OCR, image analysis) wastes time, and path-based caches break whenever files are moved or renamed. This Skill provides a pattern for caching processing results keyed by file content, so cache entries survive renames and invalidate automatically when content changes. ## Core Features & Use Cases - Content-Hash Cache Keys: Uses chunked SHA-256 hashing of file contents so cache hits survive file moves and renames, with automatic invalidation on content change. - File-Based Storage: Stores each entry as {hash}.json for O(1) lookup with no index file, treating corrupted entries as cache misses. - Service Layer Separation: Keeps extraction functions pure and wraps caching in a separate service layer, supporting --cache/--no-cache CLI options. - Use Case: A CLI tool that extracts text from hundreds of PDFs across repeated runs can skip re-parsing unchanged files even after the folder is reorganized. ## Quick Start Add content-hash based caching to my PDF text extraction pipeline so repeated runs skip unchanged files.

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 in Python?

Compute a SHA-256 hash of the file contents and use it as the cache key, storing results as `{hash}.json` files in a cache directory. Wrap the pure processing function in a service layer that checks the cache before running extraction.

Why use content hash instead of file path for caching?

Content-hash keys survive file moves and renames because the key depends on file contents, not location. They also invalidate automatically when content changes, eliminating stale cache entries without an index file.

How do I hash large files without loading them into memory?

Read the file in fixed-size chunks (e.g., 64KB) and feed each chunk to hashlib's sha256 update method. This keeps memory usage constant regardless of file size.

What happens when a cache file is corrupted?

The read function catches JSON decode and key errors and returns None, treating corruption as a cache miss. The file is simply re-processed on the next run instead of crashing.

When should I not use content-hash caching?

Avoid it for data that must always be fresh, for extremely large cache entries better handled by streaming, and when results depend on parameters beyond file content such as different extraction configurations.