jpskill.com
💬 コミュニケーション コミュニティ

remix-cache

RemixアプリケーションでRedisを活用したキャッシュを効率的に管理し、SSEによるリアルタイムな無効化、stale-while-revalidate、パターンマッチング、Reactの自動再検証などを実現することで、高速で最新のデータを提供するSkill。

📜 元の英語説明(参考)

A type-safe, Redis-backed caching library for Remix applications with SSE-based real-time invalidation, stale-while-revalidate, pattern matching, and automatic React revalidation. Use when working with Remix caching, Redis, cache invalidation, implementing caching strategies, or real-time data synchronization in Remix apps.

🇯🇵 日本人クリエイター向け解説

一言でいうと

RemixアプリケーションでRedisを活用したキャッシュを効率的に管理し、SSEによるリアルタイムな無効化、stale-while-revalidate、パターンマッチング、Reactの自動再検証などを実現することで、高速で最新のデータを提供するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o remix-cache.zip https://jpskill.com/download/17820.zip && unzip -o remix-cache.zip && rm remix-cache.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/17820.zip -OutFile "$d\remix-cache.zip"; Expand-Archive "$d\remix-cache.zip" -DestinationPath $d -Force; ri "$d\remix-cache.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して remix-cache.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → remix-cache フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
2

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Remix Cache Skill

Remix アプリケーション向けの、本番環境で使用可能なキャッシングライブラリである remix-cache の使用に関する専門的なガイダンスです。

この Skill を使用するタイミング

ユーザーが以下について質問した場合に、この Skill を使用してください。

  • Remix アプリケーションでのキャッシングの実装
  • Redis をバックエンドとしたキャッシング戦略
  • キャッシュの無効化(キー、タグ、またはパターンによる)
  • SSE によるリアルタイムキャッシュ同期
  • Stale-while-revalidate パターン
  • タイプセーフなキャッシュ定義
  • 自動再検証のための React フック
  • キャッシュによるパフォーマンス最適化
  • サーバー vs サーバーレスのキャッシングモード
  • キャッシュ障害に対するサーキットブレーカーパターン

クイックリファレンス

基本的な設定

// app/cache.server.ts
import { createCache } from 'remix-cache/server'

export const cache = createCache({
  redis: { host: process.env.REDIS_HOST, port: 6379 },
  prefix: 'myapp',
})

export const userCache = cache.define({
  name: 'user',
  key: (userId: string) => userId,
  fetch: async (userId: string) => db.user.findUnique({ where: { id: userId } }),
  ttl: 300,
})

ローダーでの使用

export async function loader({ params }: LoaderFunctionArgs) {
  const user = await userCache.get(params.userId)
  return json({ user })
}

無効化

// By key
await cache.invalidate({ key: 'myapp:user:123' })

// By tag
await cache.invalidateByTag('product')

// By pattern
await cache.invalidateByPattern('user:*')

リアルタイム React 再検証

// app/root.tsx
<CacheProvider endpoint="/api/cache-events">
  <Outlet />
</CacheProvider>

// Component
useCache({ tags: ['user'], debounce: 200 })

詳細なドキュメント

特定のトピックに関する包括的なガイダンスについては、以下を参照してください。

  • GETTING_STARTED.md - インストール、セットアップ、および最初のキャッシュ定義
  • API_REFERENCE.md - すべてのメソッドとオプションに関する完全な API ドキュメント
  • PATTERNS.md - 一般的なキャッシングパターンとベストプラクティス
  • REACT_INTEGRATION.md - リアルタイム無効化のための SSE セットアップと React フック
  • EXAMPLES.md - 実際の例(e コマース、セッション、API キャッシング)
  • TROUBLESHOOTING.md - 一般的な問題と解決策
  • TESTING.md - テスト戦略とパターン

主な機能

1. タイプセーフなキャッシュ定義

キャッシュキーと値に対する完璧な TypeScript 推論。 API_REFERENCE.md を参照してください。

2. 高度な TTL 戦略

  • Stale-while-revalidate: 新鮮なデータをフェッチしながら、古いデータを提供します
  • Sliding window: アクセスごとに TTL をリセットします
  • Conditional TTL: データに基づいた動的な TTL PATTERNS.md を参照してください。

3. 多段階の無効化

  • By key: 特定のエントリを無効化します
  • By tag: 関連するエントリのグループを無効化します
  • By pattern: グロブパターンを使用して無効化します
  • Cascading: 自動的な依存関係の無効化 API_REFERENCE.md を参照してください。

4. リアルタイム同期

  • SSE endpoint: 無効化イベントをクライアントにストリーミングします
  • React hooks: キャッシュの変更時に自動的に再検証します
  • Filtering: 特定のキー/タグ/パターンに対してのみ再検証します REACT_INTEGRATION.md を参照してください。

5. 復元力機能

  • Circuit breaker: Redis が失敗した場合のグレースフルデグラデーション
  • Request deduplication: キャッシュスタンピードを防止します
  • Error events: 障害を監視および追跡します PATTERNS.md を参照してください。

6. デプロイメントの柔軟性

  • Server mode: 2 段階のキャッシング(ローカル LRU + Redis)
  • Serverless mode: バージョン管理されたキーを持つ Redis のみ API_REFERENCE.md を参照してください。

このリポジトリのファイル構造

remix-cache ライブラリは次のように構成されています。

src/
├── server/           # サーバー側のキャッシュ実装
│   ├── cache.ts      # メインキャッシュクラス
│   ├── definition.ts # キャッシュ定義の実装
│   ├── sse-handler.ts # SSE エンドポイントジェネレーター
│   ├── local-cache.ts # インメモリ LRU キャッシュ
│   ├── circuit-breaker.ts # サーキットブレーカーパターン
│   └── deduplicator.ts # リクエストの重複排除
├── react/            # React 統合
│   ├── provider.tsx  # CacheProvider コンポーネント
│   ├── use-cache.ts  # useCache フック
│   └── context.tsx   # React コンテキスト
├── types/            # TypeScript 型定義
│   ├── cache.ts
│   ├── definition.ts
│   └── events.ts
└── utils/            # ユーティリティ関数
    ├── key-builder.ts     # キャッシュキーの生成
    ├── pattern-match.ts   # グロブパターンマッチング
    └── env-detect.ts      # 環境検出

一般的なワークフロー

新しいキャッシュの設定

  1. 基本的なセットアップについては、GETTING_STARTED.md をお読みください
  2. app/cache.server.ts にキャッシュインスタンスを作成します
  3. データ型に対してキャッシュ定義を定義します
  4. ローダー/アクションで使用します
  5. リアルタイム無効化のために SSE エンドポイントを設定します (REACT_INTEGRATION.md を参照)
  6. 自動再検証が必要なコンポーネントに React フックを追加します

キャッシュの無効化の実装

  1. 無効化戦略(キー/タグ/パターン)を特定します
  2. 必要に応じて、キャッシュ定義にタグを追加します
  3. アクションで無効化メソッドを呼び出します
  4. 無効化イベントが発火されることを確認します
  5. React コンポーネントが正しく再検証されることをテストします

キャッシュの問題のデバッグ

  1. 一般的な問題については、TROUBLESHOOTING.md を確認してください
  2. イベントリスナーを有効にして、キャッシュの動作を監視します
  3. Redis の接続と構成を確認します
  4. サーキットブレーカーの状態を確認します
  5. ブラウザの DevTools で SSE 接続を検査します

テストの作成

以下については、TESTING.md を参照してください。

  • キャッシュ定義のユニットテスト
  • Redis との統合テスト
  • テストでのキャッシュのモック
  • 無効化ロジックのテスト
  • キャッシュを使用した React コンポーネントのテスト

環境変数

REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=your-password
CACHE_PREFIX=myapp
CACHE_DEFAULT_TTL=300
NODE_ENV=production

実装に関する注意

ユーザーが remix-cache を実装するのを支援する場合:

  1. **常に型を確保してください

(原文がここで切り詰められています)

📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Remix Cache Skill

Expert guidance for using remix-cache, a production-ready caching library for Remix applications.

When to use this skill

Use this skill when the user asks about:

  • Implementing caching in Remix applications
  • Redis-backed caching strategies
  • Cache invalidation (by key, tag, or pattern)
  • Real-time cache synchronization with SSE
  • Stale-while-revalidate patterns
  • Type-safe cache definitions
  • React hooks for automatic revalidation
  • Performance optimization with caching
  • Server vs serverless caching modes
  • Circuit breaker patterns for cache failures

Quick reference

Basic setup

// app/cache.server.ts
import { createCache } from 'remix-cache/server'

export const cache = createCache({
  redis: { host: process.env.REDIS_HOST, port: 6379 },
  prefix: 'myapp',
})

export const userCache = cache.define({
  name: 'user',
  key: (userId: string) => userId,
  fetch: async (userId: string) => db.user.findUnique({ where: { id: userId } }),
  ttl: 300,
})

Use in loaders

export async function loader({ params }: LoaderFunctionArgs) {
  const user = await userCache.get(params.userId)
  return json({ user })
}

Invalidation

// By key
await cache.invalidate({ key: 'myapp:user:123' })

// By tag
await cache.invalidateByTag('product')

// By pattern
await cache.invalidateByPattern('user:*')

Real-time React revalidation

// app/root.tsx
<CacheProvider endpoint="/api/cache-events">
  <Outlet />
</CacheProvider>

// Component
useCache({ tags: ['user'], debounce: 200 })

Detailed documentation

For comprehensive guidance on specific topics, see:

Key capabilities

1. Type-safe cache definitions

Perfect TypeScript inference for cache keys and values. See API_REFERENCE.md.

2. Advanced TTL strategies

  • Stale-while-revalidate: Serve stale data while fetching fresh
  • Sliding window: Reset TTL on each access
  • Conditional TTL: Dynamic TTL based on data See PATTERNS.md.

3. Multi-level invalidation

  • By key: Invalidate specific entries
  • By tag: Invalidate groups of related entries
  • By pattern: Invalidate using glob patterns
  • Cascading: Automatic dependent invalidation See API_REFERENCE.md.

4. Real-time synchronization

  • SSE endpoint: Stream invalidation events to clients
  • React hooks: Automatic revalidation on cache changes
  • Filtering: Revalidate only for specific keys/tags/patterns See REACT_INTEGRATION.md.

5. Resilience features

  • Circuit breaker: Graceful degradation when Redis fails
  • Request deduplication: Prevent cache stampede
  • Error events: Monitor and track failures See PATTERNS.md.

6. Deployment flexibility

  • Server mode: Two-tier caching (local LRU + Redis)
  • Serverless mode: Redis-only with versioned keys See API_REFERENCE.md.

File structure in this repository

The remix-cache library is organized as:

src/
├── server/           # Server-side cache implementation
│   ├── cache.ts      # Main cache class
│   ├── definition.ts # Cache definition implementation
│   ├── sse-handler.ts # SSE endpoint generator
│   ├── local-cache.ts # In-memory LRU cache
│   ├── circuit-breaker.ts # Circuit breaker pattern
│   └── deduplicator.ts # Request deduplication
├── react/            # React integration
│   ├── provider.tsx  # CacheProvider component
│   ├── use-cache.ts  # useCache hook
│   └── context.tsx   # React context
├── types/            # TypeScript type definitions
│   ├── cache.ts
│   ├── definition.ts
│   └── events.ts
└── utils/            # Utility functions
    ├── key-builder.ts     # Cache key generation
    ├── pattern-match.ts   # Glob pattern matching
    └── env-detect.ts      # Environment detection

Common workflows

Setting up a new cache

  1. Read GETTING_STARTED.md for basic setup
  2. Create cache instance in app/cache.server.ts
  3. Define cache definitions for your data types
  4. Use in loaders/actions
  5. Set up SSE endpoint for real-time invalidation (see REACT_INTEGRATION.md)
  6. Add React hooks to components that need auto-revalidation

Implementing cache invalidation

  1. Identify invalidation strategy (key/tag/pattern)
  2. Add tags to cache definitions if needed
  3. Call invalidation methods in actions
  4. Verify invalidation events are fired
  5. Test React components revalidate correctly

Debugging cache issues

  1. Check TROUBLESHOOTING.md for common issues
  2. Enable event listeners to monitor cache behavior
  3. Verify Redis connection and configuration
  4. Check circuit breaker state
  5. Inspect SSE connection in browser DevTools

Writing tests

See TESTING.md for:

  • Unit testing cache definitions
  • Integration testing with Redis
  • Mocking cache in tests
  • Testing invalidation logic
  • Testing React components with cache

Environment variables

REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=your-password
CACHE_PREFIX=myapp
CACHE_DEFAULT_TTL=300
NODE_ENV=production

Implementation notes

When helping users implement remix-cache:

  1. Always ensure type safety: The library provides perfect TypeScript inference
  2. Consider deployment mode: Ask if serverless or server-based
  3. Plan invalidation strategy: Tags are more flexible than keys
  4. Set appropriate TTLs: Balance freshness with performance
  5. Monitor errors: Always set up error event listeners
  6. Test thoroughly: Cache bugs can be subtle, see TESTING.md
  7. Close connections: Especially important in tests

Getting help

For specific topics:

Version

This skill covers remix-cache v0.1.0 with complete implementation of Phases 1-5:

  • ✅ Core caching with Redis backend
  • ✅ Type-safe cache definitions
  • ✅ Stale-while-revalidate
  • ✅ Sliding window TTL
  • ✅ Pattern & tag-based invalidation
  • ✅ Circuit breaker pattern
  • ✅ Request deduplication
  • ✅ Server/serverless modes
  • ✅ SSE real-time invalidation
  • ✅ React hooks for auto-revalidation

同梱ファイル

※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。