Content-Hash File Caching Pattern
Implements high-performance, path-independent file caching using SHA-256 content hashes to optimize expensive data processing tasks.
The Content-Hash File Cache Pattern provides a robust framework for caching expensive file operations like PDF parsing, OCR, and image analysis. By using SHA-256 hashes of file contents as cache keys instead of file paths, this pattern ensures cache hits even when files are renamed or moved, while automatically invalidating entries when content changes. It emphasizes a clean service layer separation, keeping core processing logic pure while providing a scalable, O(1) lookup mechanism for processed results.
Key Features
01Service layer separation to maintain pure processing functions
02Graceful degradation with corruption handling and chunked hashing
03Path-independent caching based on SHA-256 content signatures
04151 GitHub stars
05Automatic cache invalidation upon any file content modification
06O(1) lookup performance using individual hash-named JSON files
Use Cases
01Caching results from expensive PDF text extraction or OCR workflows
02Building data pipelines where identical files appear across different directories
03Optimizing CLI tools with --cache flags for repeated runs