affaan-m/ECC

content-hash-cache-pattern

SHA-256コンテンツハッシュを使用して、高コストなファイル処理結果をキャッシュします — パス非依存、自動無効化、サービスレイヤーの分離。

68Collecting
See how to use itView GitHub source
npx skills add https://github.com/affaan-m/ECC --skill "docs/ja-JP/skills/content-hash-cache-pattern"
Automated source guide

Source checked Jul 28, 2026·Refresh due Oct 26, 2026

Reorganized from the pinned upstream SKILL.md

Turn content-hash-cache-pattern's source instructions into a guide you can follow

According to the pinned SKILL.md from affaan-m/ECC: SHA-256コンテンツハッシュをキャッシュキーとして使用して、高コストなファイル処理結果(PDF解析、テキスト抽出、画像分析)をキャッシュします。パスベースのキャッシュとは異なり、このアプローチはファイルの移動/名前変更に対して生き残り、コンテンツが変更されたときに自動的に無効化されます。

npx skills add https://github.com/affaan-m/ECC --skill "docs/ja-JP/skills/content-hash-cache-pattern"
Check the pinned source

Best fit

  • SHA-256コンテンツハッシュを使用して、高コストなファイル処理結果をキャッシュします — パス非依存、自動無効化、サービスレイヤーの分離。

Bring this context

  • A concrete task that matches the documented purpose of content-hash-cache-pattern.
  • The files, examples, or context the task depends on.
  • Your constraints, target environment, and definition of done.

Expected outputs

  • A result that follows the pinned content-hash-cache-pattern instructions.
  • A concise record of assumptions, inputs used, and unresolved questions.
  • A final check against the source workflow and relevant permission signals.

Key source sections

Read content-hash-cache-pattern through these 5 source sections

Sections are extracted automatically from the pinned SKILL.md and link back to the source.

01

起動条件

ファイル処理パイプラインの構築(PDF、画像、テキスト抽出)

SKILL.md · 起動条件
ファイル処理パイプラインの構築(PDF、画像、テキスト抽出)処理コストが高く、同じファイルが繰り返し処理される場合--cache/--no-cacheCLIオプションが必要な場合
02

コアパターン

パスではなくファイルコンテンツをキャッシュキーとして使用します:

SKILL.md · コアパターン
パスではなくファイルコンテンツをキャッシュキーとして使用します:なぜコンテンツハッシュ? ファイルの名前変更/移動 = キャッシュヒット。コンテンツ変更 = 自動無効化。インデックスファイル不要。各キャッシュエントリは{hash}.jsonとして保存されます — ハッシュによるO(1)検索、インデックスファイル不要。
03

1. コンテンツハッシュベースのキャッシュキー

パスではなくファイルコンテンツをキャッシュキーとして使用します:

SKILL.md · 1. コンテンツハッシュベースのキャッシュキー
パスではなくファイルコンテンツをキャッシュキーとして使用します:なぜコンテンツハッシュ? ファイルの名前変更/移動 = キャッシュヒット。コンテンツ変更 = 自動無効化。インデックスファイル不要。
04

2. キャッシュエントリの凍結データクラス

Review the “2. キャッシュエントリの凍結データクラス” section in the pinned source before continuing.

SKILL.md · 2. キャッシュエントリの凍結データクラス
Review and apply the “2. キャッシュエントリの凍結データクラス” source section.
05

3. ファイルベースのキャッシュストレージ

各キャッシュエントリは{hash}.jsonとして保存されます — ハッシュによるO(1)検索、インデックスファイル不要。

SKILL.md · 3. ファイルベースのキャッシュストレージ
各キャッシュエントリは{hash}.jsonとして保存されます — ハッシュによるO(1)検索、インデックスファイル不要。

SkillSignal prompt templates

Provide the task, context, and acceptance criteria

These prompts were written by SkillSignal from the source structure; they are not upstream text.

Task-start prompt

Confirm source fit, inputs, and outputs before acting.

Use content-hash-cache-pattern to help me with: [specific task]. Context: [files, data, or background]. Constraints: [environment, scope, and prohibited actions]. Before acting, check the pinned SKILL.md and explain which sections apply, what inputs are still missing, and what you will deliver.

Source-guided execution

Make the Agent explicitly follow the key extracted sections.

Apply the pinned content-hash-cache-pattern source to [task]. Pay particular attention to these source sections: “起動条件”, “コアパターン”, “1. コンテンツハッシュベースのキャッシュキー”, “2. キャッシュエントリの凍結データクラス”, “3. ファイルベースのキャッシュストレージ”. Preserve the important decision at each step. Mark facts not covered by the source as “needs confirmation” instead of inventing them. Then verify the result against my acceptance criteria: [criteria].

Result-review prompt

Check omissions, permissions, and source drift before delivery.

Review the current content-hash-cache-pattern result: (1) does it satisfy the original task; (2) were any applicable steps or limits in the pinned SKILL.md missed; (3) did it perform any unauthorized file, command, network, or data action; and (4) which conclusions remain unverified? List issues first, then fix only what the source or user authorization supports.

Output checklist

Verify each item before delivery

The task matches the purpose documented in the SKILL.md.

The source section “起動条件” has been checked.

The source section “コアパターン” has been checked.

The source section “1. コンテンツハッシュベースのキャッシュキー” has been checked.

The source section “2. キャッシュエントリの凍結データクラス” has been checked.

Inputs, constraints, and acceptance criteria are explicit.

Unverified facts, compatibility, and outcome claims are clearly marked.

Any file, command, network, or data action has been reviewed.

Choose a different workflow

When another Skill is the better fit

FAQ

What does content-hash-cache-pattern do?

SHA-256コンテンツハッシュをキャッシュキーとして使用して、高コストなファイル処理結果(PDF解析、テキスト抽出、画像分析)をキャッシュします。パスベースのキャッシュとは異なり、このアプローチはファイルの移動/名前変更に対して生き残り、コンテンツが変更されたときに自動的に無効化されます。

How do I start using content-hash-cache-pattern?

The catalog detected this source-specific install command: npx skills add https://github.com/affaan-m/ECC --skill "docs/ja-JP/skills/content-hash-cache-pattern". Inspect the command and pinned source before running it.

Which Agent platforms does it declare?

No dedicated Agent platform is declared in the pinned source record.

Repository stars
234,327
Repository forks
35,711
Quality
68/100
Source repository last pushed

Quality breakdown

Based on traceable docs and repository signals; stars are not treated as quality.

68/100
Documentation22/30
Specificity14/25
Maintenance20/20
Trust signals12/25

Compare before choosing

Related Agent Skills and source variants

These links are selected from shared tasks, functions, stacks, platforms, and same-name variants. Compare the source owner, documentation, permissions, and maintenance signals.

content-hash-cache-pattern by affaan-m

Cache expensive file processing results using SHA-256 content hashes — path-independent, auto-invalidating, with service layer separation.

content-hash-cache-pattern by affaan-m

Cache expensive file processing results using SHA-256 content hashes — path-independent, auto-invalidating, with service layer separation.

content-hash-cache-pattern by affaan-m

使用SHA-256内容哈希缓存昂贵的文件处理结果——路径无关、自动失效、服务层分离。

ab-testing by coreyhaines31

When the user wants to plan, design, or implement an A/B test or experiment, or build a growth experimentation program. Also use when the user mentions "A/B test," "split test," "experiment," "test this change," "variant copy," "multivariate test," "hypothesis," "should I test this," "which version is better," "test two versions," "statistical significance," "how long should I run this test," "growth experiments," "experiment velocity," "experiment backlog," "ICE score," "experimentation program

churn-prevention by coreyhaines31

When the user wants to reduce churn, build cancellation flows, set up save offers, recover failed payments, or implement retention strategies. Also use when the user mentions 'churn,' 'cancel flow,' 'offboarding,' 'save offer,' 'dunning,' 'failed payment recovery,' 'win-back,' 'retention,' 'exit survey,' 'pause subscription,' 'involuntary churn,' 'people keep canceling,' 'churn rate is too high,' 'how do I keep users,' or 'customers are leaving.' Use this whenever someone is losing subscribers o

View original Skill.mdThis page is parsed directly from the repository SKILL.md without editorial rewriting. Collected: Jul 28, 2026 · about 1 min

コンテンツハッシュファイルキャッシュパターン

SHA-256コンテンツハッシュをキャッシュキーとして使用して、高コストなファイル処理結果(PDF解析、テキスト抽出、画像分析)をキャッシュします。パスベースのキャッシュとは異なり、このアプローチはファイルの移動/名前変更に対して生き残り、コンテンツが変更されたときに自動的に無効化されます。

起動条件

  • ファイル処理パイプラインの構築(PDF、画像、テキスト抽出)
  • 処理コストが高く、同じファイルが繰り返し処理される場合
  • --cache/--no-cacheCLIオプションが必要な場合
  • 既存の純粋な関数を変更せずにキャッシュを追加したい場合

コアパターン

1. コンテンツハッシュベースのキャッシュキー

パスではなくファイルコンテンツをキャッシュキーとして使用します:

import hashlib
from pathlib import Path

_HASH_CHUNK_SIZE = 65536  # 大きなファイルには64KBチャンク

def compute_file_hash(path: Path) -> str:
    """ファイルコンテンツのSHA-256(大きなファイルにはチャンク処理)。"""
    if not path.is_file():
        raise FileNotFoundError(f"File not found: {path}")
    sha256 = hashlib.sha256()
    with open(path, "rb") as f:
        while True:
            chunk = f.read(_HASH_CHUNK_SIZE)
            if not chunk:
                break
            sha256.update(chunk)
    return sha256.hexdigest()

なぜコンテンツハッシュ? ファイルの名前変更/移動 = キャッシュヒット。コンテンツ変更 = 自動無効化。インデックスファイル不要。

2. キャッシュエントリの凍結データクラス

from dataclasses import dataclass

@dataclass(frozen=True, slots=True)
class CacheEntry:
    file_hash: str
    source_path: str
    document: ExtractedDocument  # キャッシュされた結果

3. ファイルベースのキャッシュストレージ

各キャッシュエントリは{hash}.jsonとして保存されます — ハッシュによるO(1)検索、インデックスファイル不要。

import json
from typing import Any

def write_cache(cache_dir: Path, entry: CacheEntry) -> None:
    cache_dir.mkdir(parents=True, exist_ok=True)
    cache_file = cache_dir / f"{entry.file_hash}.json"
    data = serialize_entry(entry)
    cache_file.write_text(json.dumps(data, ensure_ascii=False), encoding="utf-8")

def read_cache(cache_dir: Path, file_hash: str) -> CacheEntry | None:
    cache_file = cache_dir / f"{file_hash}.json"
    if not cache_file.is_file():
        return None
    try:
        raw = cache_file.read_text(encoding="utf-8")
        data = json.loads(raw)
        return deserialize_entry(data)
    except (json.JSONDecodeError, ValueError, KeyError):
        return None  # 破損をキャッシュミスとして扱う

4. サービスレイヤーラッパー(SRP)

処理関数を純粋に保ちます。キャッシュを別のサービスレイヤーとして追加します。

def extract_with_cache(
    file_path: Path,
    *,
    cache_enabled: bool = True,
    cache_dir: Path = Path(".cache"),
) -> ExtractedDocument:
    """サービスレイヤー: キャッシュチェック -> 抽出 -> キャッシュ書き込み。"""
    if not cache_enabled:
        return extract_text(file_path)  # 純粋な関数、キャッシュの知識なし

    file_hash = compute_file_hash(file_path)

    # キャッシュを確認
    cached = read_cache(cache_dir, file_hash)
    if cached is not None:
        logger.info("Cache hit: %s (hash=%s)", file_path.name, file_hash[:12])
        return cached.document

    # キャッシュミス -> 抽出 -> 保存
    logger.info("Cache miss: %s (hash=%s)", file_path.name, file_hash[:12])
    doc = extract_text(file_path)
    entry = CacheEntry(file_hash=file_hash, source_path=str(file_path), document=doc)
    write_cache(cache_dir, entry)
    return doc

主要な設計上の決定

決定根拠
SHA-256コンテンツハッシュパス非依存、コンテンツ変更で自動無効化
{hash}.jsonファイル命名O(1)検索、インデックスファイル不要
サービスレイヤーラッパーSRP: 抽出は純粋に保ち、キャッシュは別の関心事
手動JSONシリアル化凍結データクラスのシリアル化を完全制御
破損はNoneを返すグレースフルデグラデーション、次回の実行で再処理
cache_dir.mkdir(parents=True)最初の書き込み時に遅延ディレクトリ作成

ベストプラクティス

  • パスではなくコンテンツをハッシュ — パスは変わるが、コンテンツのアイデンティティは変わらない
  • 大きなファイルはチャンク処理でハッシュ — ファイル全体をメモリに読み込まないようにする
  • 処理関数を純粋に保つ — キャッシュについて何も知らないようにする
  • 切り捨てたハッシュでキャッシュヒット/ミスをログ記録 — デバッグのため
  • 破損をグレースフルに処理 — 無効なキャッシュエントリはミスとして扱い、クラッシュしない

避けるべきアンチパターン

# 悪い例: パスベースのキャッシュ(ファイルの移動/名前変更で壊れる)
cache = {"/path/to/file.pdf": result}

# 悪い例: 処理関数内にキャッシュロジックを追加(SRP違反)
def extract_text(path, *, cache_enabled=False, cache_dir=None):
    if cache_enabled:  # この関数は今や2つの責任を持っている
        ...

# 悪い例: ネストされた凍結データクラスでdataclasses.asdict()を使用
# (複雑なネストされた型で問題を引き起こす可能性がある)
data = dataclasses.asdict(entry)  # 代わりに手動シリアル化を使用

使用すべき場合

  • ファイル処理パイプライン(PDF解析、OCR、テキスト抽出、画像分析)
  • --cache/--no-cacheオプションが有益なCLIツール
  • 同じファイルが複数回にわたって現れるバッチ処理
  • 既存の純粋な関数を変更せずにキャッシュを追加する場合

使用すべきでない場合

  • 常に最新でなければならないデータ(リアルタイムフィード)
  • 非常に大きなキャッシュエントリ(代わりにストリーミングを検討)
  • ファイルコンテンツ以外のパラメータに依存する結果(例:異なる抽出設定)
Source repo
affaan-m/ECC
Skill path
docs/ja-JP/skills/content-hash-cache-pattern/SKILL.md
Commit SHA
4e973d3eaf92
Repository license
MIT
Data collected