[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M719K6SN9RM4TCTPFDWWZ1RT":3,"skill-same:01M719K6SN9RM4TCTPFDWWZ1RT":59},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":31,"linkOnly":32,"markdownContent":33,"markdownBody":34,"frontMatter":35,"refName":39,"commitSha":40,"skillDirectory":41,"forksCount":14,"repositoryHtmlUrl":42,"repositoryHomepageUrl":6,"ownerHtmlUrl":43,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":44,"install":45,"resources":58},"01M719K6SN9RM4TCTPFDWWZ1RT","prompt-caching",null,"Caching strategies for LLM prompts including Anthropic prompt caching, response caching, and CAG (Cache Augmented Generation)","sapsapshen\u002Fai-memory-router","sapsapshen","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F20347959?v=4","01M6XDQEF1DP50DKF37H81J3J5","shenmian","01M6XDQEJPE41Y3DT2763X8ZJN",0,"MIT","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fglobal\u002Fprompt-caching\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30],"prompt caching","prompt","caching","apache","cache","prompts","strategies","caching strategies","generation","for","spawner","2026","2026-11-10 10:12:30",false,"---\nname: prompt-caching\ndescription: Caching strategies for LLM prompts including Anthropic prompt\n  caching, response caching, and CAG (Cache Augmented Generation)\nrisk: none\nsource: vibeship-spawner-skills (Apache 2.0)\ndate_added: 2026-02-27\n---\n\n# Prompt Caching\n\nCaching strategies for LLM prompts including Anthropic prompt caching, response caching, and CAG (Cache Augmented Generation)\n\n## Capabilities\n\n- prompt-cache\n- response-cache\n- kv-cache\n- cag-patterns\n- cache-invalidation\n\n## Prerequisites\n\n- Knowledge: Caching fundamentals, LLM API usage, Hash functions\n- Skills_recommended: context-window-management\n\n## Scope\n\n- Does_not_cover: CDN caching, Database query caching, Static asset caching\n- Boundaries: Focus is LLM-specific caching, Covers prompt and response caching\n\n## Ecosystem\n\n### Primary_tools\n\n- Anthropic Prompt Caching - Native prompt caching in Claude API\n- Redis - In-memory cache for responses\n- OpenAI Caching - Automatic caching in OpenAI API\n\n## Patterns\n\n### Anthropic Prompt Caching\n\nUse Claude's native prompt caching for repeated prefixes\n\n**When to use**: Using Claude API with stable system prompts or context\n\nimport Anthropic from '@anthropic-ai\u002Fsdk';\n\nconst client = new Anthropic();\n\n\u002F\u002F Cache the stable parts of your prompt\nasync function queryWithCaching(userQuery: string) {\n    const response = await client.messages.create({\n        model: \"claude-sonnet-4-20250514\",\n        max_tokens: 1024,\n        system: [\n            {\n                type: \"text\",\n                text: LONG_SYSTEM_PROMPT,  \u002F\u002F Your detailed instructions\n                cache_control: { type: \"ephemeral\" }  \u002F\u002F Cache this!\n            },\n            {\n                type: \"text\",\n                text: KNOWLEDGE_BASE,  \u002F\u002F Large static context\n                cache_control: { type: \"ephemeral\" }\n            }\n        ],\n        messages: [\n            { role: \"user\", content: userQuery }  \u002F\u002F Dynamic part\n        ]\n    });\n\n    \u002F\u002F Check cache usage\n    console.log(`Cache read: ${response.usage.cache_read_input_tokens}`);\n    console.log(`Cache write: ${response.usage.cache_creation_input_tokens}`);\n\n    return response;\n}\n\n\u002F\u002F Cost savings: 90% reduction on cached tokens\n\u002F\u002F Latency savings: Up to 2x faster\n\n### Response Caching\n\nCache full LLM responses for identical or similar queries\n\n**When to use**: Same queries asked repeatedly\n\nimport { createHash } from 'crypto';\nimport Redis from 'ioredis';\n\nconst redis = new Redis(process.env.REDIS_URL);\n\nclass ResponseCache {\n    private ttl = 3600;  \u002F\u002F 1 hour default\n\n    \u002F\u002F Exact match caching\n    async getCached(prompt: string): Promise\u003Cstring | null> {\n        const key = this.hashPrompt(prompt);\n        return await redis.get(`response:${key}`);\n    }\n\n    async setCached(prompt: string, response: string): Promise\u003Cvoid> {\n        const key = this.hashPrompt(prompt);\n        await redis.set(`response:${key}`, response, 'EX', this.ttl);\n    }\n\n    private hashPrompt(prompt: string): string {\n        return createHash('sha256').update(prompt).digest('hex');\n    }\n\n    \u002F\u002F Semantic similarity caching\n    async getSemanticallySimilar(\n        prompt: string,\n        threshold: number = 0.95\n    ): Promise\u003Cstring | null> {\n        const embedding = await embed(prompt);\n        const similar = await this.vectorCache.search(embedding, 1);\n\n        if (similar.length && similar[0].similarity > threshold) {\n            return await redis.get(`response:${similar[0].id}`);\n        }\n        return null;\n    }\n\n    \u002F\u002F Temperature-aware caching\n    async getCachedWithParams(\n        prompt: string,\n        params: { temperature: number; model: string }\n    ): Promise\u003Cstring | null> {\n        \u002F\u002F Only cache low-temperature responses\n        if (params.temperature > 0.5) return null;\n\n        const key = this.hashPrompt(\n            `${prompt}|${params.model}|${params.temperature}`\n        );\n        return await redis.get(`response:${key}`);\n    }\n}\n\n### Cache Augmented Generation (CAG)\n\nPre-cache documents in prompt instead of RAG retrieval\n\n**When to use**: Document corpus is stable and fits in context\n\n\u002F\u002F CAG: Pre-compute document context, cache in prompt\n\u002F\u002F Better than RAG when:\n\u002F\u002F - Documents are stable\n\u002F\u002F - Total fits in context window\n\u002F\u002F - Latency is critical\n\nclass CAGSystem {\n    private cachedContext: string | null = null;\n    private lastUpdate: number = 0;\n\n    async buildCachedContext(documents: Document[]): Promise\u003Cvoid> {\n        \u002F\u002F Pre-process and format documents\n        const formatted = documents.map(d =>\n            `## ${d.title}\\n${d.content}`\n        ).join('\\n\\n');\n\n        \u002F\u002F Store with timestamp\n        this.cachedContext = formatted;\n        this.lastUpdate = Date.now();\n    }\n\n    async query(userQuery: string): Promise\u003Cstring> {\n        \u002F\u002F Use cached context directly in prompt\n        const response = await client.messages.create({\n            model: \"claude-sonnet-4-20250514\",\n            max_tokens: 1024,\n            system: [\n                {\n                    type: \"text\",\n                    text: \"You are a helpful assistant with access to the following documentation.\",\n                    cache_control: { type: \"ephemeral\" }\n                },\n                {\n                    type: \"text\",\n                    text: this.cachedContext!,  \u002F\u002F Pre-cached docs\n                    cache_control: { type: \"ephemeral\" }\n                }\n            ],\n            messages: [{ role: \"user\", content: userQuery }]\n        });\n\n        return response.content[0].text;\n    }\n\n    \u002F\u002F Periodic refresh\n    async refreshIfNeeded(documents: Document[]): Promise\u003Cvoid> {\n        const stale = Date.now() - this.lastUpdate > 3600000;  \u002F\u002F 1 hour\n        if (stale) {\n            await this.buildCachedContext(documents);\n        }\n    }\n}\n\n\u002F\u002F CAG vs RAG decision matrix:\n\u002F\u002F | Factor           | CAG Better | RAG Better |\n\u002F\u002F |------------------|------------|------------|\n\u002F\u002F | Corpus size      | \u003C 100K tokens | > 100K tokens |\n\u002F\u002F | Update frequency | Low | High |\n\u002F\u002F | Latency needs    | Critical | Flexible |\n\u002F\u002F | Query specificity| General | Specific |\n\n## Sharp Edges\n\n### Cache miss causes latency spike with additional overhead\n\nSeverity: HIGH\n\nSituation: Slow response when cache miss, slower than no caching\n\nSymptoms:\n- Slow responses on cache miss\n- Cache hit rate below 50%\n- Higher latency than uncached\n\nWhy this breaks:\nCache check adds latency.\nCache write adds more latency.\nMiss + overhead > no caching.\n\nRecommended fix:\n\n\u002F\u002F Optimize for cache misses, not just hits\n\nclass OptimizedCache {\n    async queryWithCache(prompt: string): Promise\u003Cstring> {\n        const cacheKey = this.hash(prompt);\n\n        \u002F\u002F Non-blocking cache check\n        const cachedPromise = this.cache.get(cacheKey);\n        const llmPromise = this.queryLLM(prompt);\n\n        \u002F\u002F Race: use cache if available before LLM returns\n        const cached = await Promise.race([\n            cachedPromise,\n            sleep(50).then(() => null)  \u002F\u002F 50ms cache timeout\n        ]);\n\n        if (cached) {\n            \u002F\u002F Cancel LLM request if possible\n            return cached;\n        }\n\n        \u002F\u002F Cache miss: continue with LLM\n        const response = await llmPromise;\n\n        \u002F\u002F Async cache write (don't block response)\n        this.cache.set(cacheKey, response).catch(console.error);\n\n        return response;\n    }\n}\n\n\u002F\u002F Alternative: Probabilistic caching\n\u002F\u002F Only cache if query matches known high-frequency patterns\nclass SelectiveCache {\n    private patterns: Map\u003Cstring, number> = new Map();\n\n    shouldCache(prompt: string): boolean {\n        const pattern = this.extractPattern(prompt);\n        const frequency = this.patterns.get(pattern) || 0;\n\n        \u002F\u002F Only cache high-frequency patterns\n        return frequency > 10;\n    }\n\n    recordQuery(prompt: string): void {\n        const pattern = this.extractPattern(prompt);\n        this.patterns.set(pattern, (this.patterns.get(pattern) || 0) + 1);\n    }\n}\n\n### Cached responses become incorrect over time\n\nSeverity: HIGH\n\nSituation: Users get outdated or wrong information from cache\n\nSymptoms:\n- Users report wrong information\n- Answers don't match current data\n- Complaints about outdated responses\n\nWhy this breaks:\nSource data changed.\nNo cache invalidation.\nLong TTLs for dynamic data.\n\nRecommended fix:\n\n\u002F\u002F Implement proper cache invalidation\n\nclass InvalidatingCache {\n    \u002F\u002F Version-based invalidation\n    private cacheVersion = 1;\n\n    getCacheKey(prompt: string): string {\n        return `v${this.cacheVersion}:${this.hash(prompt)}`;\n    }\n\n    invalidateAll(): void {\n        this.cacheVersion++;\n        \u002F\u002F Old keys automatically become orphaned\n    }\n\n    \u002F\u002F Content-hash invalidation\n    async setWithContentHash(\n        key: string,\n        response: string,\n        sourceContent: string\n    ): Promise\u003Cvoid> {\n        const contentHash = this.hash(sourceContent);\n        await this.cache.set(key, {\n            response,\n            contentHash,\n            timestamp: Date.now()\n        });\n    }\n\n    async getIfValid(\n        key: string,\n        currentSourceContent: string\n    ): Promise\u003Cstring | null> {\n        const cached = await this.cache.get(key);\n        if (!cached) return null;\n\n        \u002F\u002F Check if source content changed\n        const currentHash = this.hash(currentSourceContent);\n        if (cached.contentHash !== currentHash) {\n            await this.cache.delete(key);\n            return null;\n        }\n\n        return cached.response;\n    }\n\n    \u002F\u002F Event-based invalidation\n    onSourceUpdate(sourceId: string): void {\n        \u002F\u002F Invalidate all caches that used this source\n        this.invalidateByTag(`source:${sourceId}`);\n    }\n}\n\n### Prompt caching doesn't work due to prefix changes\n\nSeverity: MEDIUM\n\nSituation: Cache misses despite similar prompts\n\nSymptoms:\n- Cache hit rate lower than expected\n- Cache creation tokens high, read low\n- Similar prompts not hitting cache\n\nWhy this breaks:\nAnthropic caching requires exact prefix match.\nTimestamps or dynamic content in prefix.\nDifferent message order.\n\nRecommended fix:\n\n\u002F\u002F Structure prompts for optimal caching\n\nclass CacheOptimizedPrompts {\n    \u002F\u002F WRONG: Dynamic content in cached prefix\n    buildPromptBad(query: string): SystemMessage[] {\n        return [\n            {\n                type: \"text\",\n                text: `You are helpful. Current time: ${new Date()}`,  \u002F\u002F BREAKS CACHE!\n                cache_control: { type: \"ephemeral\" }\n            }\n        ];\n    }\n\n    \u002F\u002F RIGHT: Static prefix, dynamic at end\n    buildPromptGood(query: string): SystemMessage[] {\n        return [\n            {\n                type: \"text\",\n                text: STATIC_SYSTEM_PROMPT,  \u002F\u002F Never changes\n                cache_control: { type: \"ephemeral\" }\n            },\n            {\n                type: \"text\",\n                text: STATIC_KNOWLEDGE_BASE,  \u002F\u002F Rarely changes\n                cache_control: { type: \"ephemeral\" }\n            }\n            \u002F\u002F Dynamic content goes in messages, NOT system\n        ];\n    }\n\n    \u002F\u002F Prefix ordering matters\n    buildWithConsistentOrder(components: string[]): SystemMessage[] {\n        \u002F\u002F Sort components for consistent ordering\n        const sorted = [...components].sort();\n        return sorted.map((c, i) => ({\n            type: \"text\",\n            text: c,\n            cache_control: i === sorted.length - 1\n                ? { type: \"ephemeral\" }\n                : undefined  \u002F\u002F Only cache the full prefix\n        }));\n    }\n}\n\n## Validation Checks\n\n### Caching High Temperature Responses\n\nSeverity: WARNING\n\nMessage: Caching with high temperature. Responses are non-deterministic.\n\nFix action: Only cache responses with temperature \u003C= 0.5\n\n### Cache Without TTL\n\nSeverity: WARNING\n\nMessage: Cache without TTL. May serve stale data indefinitely.\n\nFix action: Set appropriate TTL based on data freshness requirements\n\n### Dynamic Content in Cached Prefix\n\nSeverity: WARNING\n\nMessage: Dynamic content in cached prefix. Will cause cache misses.\n\nFix action: Move dynamic content outside of cache_control blocks\n\n### No Cache Metrics\n\nSeverity: INFO\n\nMessage: Cache without hit\u002Fmiss tracking. Can't measure effectiveness.\n\nFix action: Add cache hit\u002Fmiss metrics and logging\n\n## Collaboration\n\n### Delegation Triggers\n\n- context window|token -> context-window-management (Need context optimization)\n- rag|retrieval -> rag-implementation (Need retrieval system)\n- memory -> conversation-memory (Need memory persistence)\n\n### High-Performance LLM System\n\nSkills: prompt-caching, context-window-management, rag-implementation\n\nWorkflow:\n\n```\n1. Analyze query patterns\n2. Implement prompt caching for stable prefixes\n3. Add response caching for frequent queries\n4. Consider CAG for stable document sets\n5. Monitor and optimize hit rates\n```\n\n## Related Skills\n\nWorks well with: `context-window-management`, `rag-implementation`, `conversation-memory`\n\n## When to Use\n\n- User mentions or implies: prompt caching\n- User mentions or implies: cache prompt\n- User mentions or implies: response cache\n- User mentions or implies: cag\n- User mentions or implies: cache augmented\n","# Prompt Caching\n\nCaching strategies for LLM prompts including Anthropic prompt caching, response caching, and CAG (Cache Augmented Generation)\n\n## Capabilities\n\n- prompt-cache\n- response-cache\n- kv-cache\n- cag-patterns\n- cache-invalidation\n\n## Prerequisites\n\n- Knowledge: Caching fundamentals, LLM API usage, Hash functions\n- Skills_recommended: context-window-management\n\n## Scope\n\n- Does_not_cover: CDN caching, Database query caching, Static asset caching\n- Boundaries: Focus is LLM-specific caching, Covers prompt and response caching\n\n## Ecosystem\n\n### Primary_tools\n\n- Anthropic Prompt Caching - Native prompt caching in Claude API\n- Redis - In-memory cache for responses\n- OpenAI Caching - Automatic caching in OpenAI API\n\n## Patterns\n\n### Anthropic Prompt Caching\n\nUse Claude's native prompt caching for repeated prefixes\n\n**When to use**: Using Claude API with stable system prompts or context\n\nimport Anthropic from '@anthropic-ai\u002Fsdk';\n\nconst client = new Anthropic();\n\n\u002F\u002F Cache the stable parts of your prompt\nasync function queryWithCaching(userQuery: string) {\n    const response = await client.messages.create({\n        model: \"claude-sonnet-4-20250514\",\n        max_tokens: 1024,\n        system: [\n            {\n                type: \"text\",\n                text: LONG_SYSTEM_PROMPT,  \u002F\u002F Your detailed instructions\n                cache_control: { type: \"ephemeral\" }  \u002F\u002F Cache this!\n            },\n            {\n                type: \"text\",\n                text: KNOWLEDGE_BASE,  \u002F\u002F Large static context\n                cache_control: { type: \"ephemeral\" }\n            }\n        ],\n        messages: [\n            { role: \"user\", content: userQuery }  \u002F\u002F Dynamic part\n        ]\n    });\n\n    \u002F\u002F Check cache usage\n    console.log(`Cache read: ${response.usage.cache_read_input_tokens}`);\n    console.log(`Cache write: ${response.usage.cache_creation_input_tokens}`);\n\n    return response;\n}\n\n\u002F\u002F Cost savings: 90% reduction on cached tokens\n\u002F\u002F Latency savings: Up to 2x faster\n\n### Response Caching\n\nCache full LLM responses for identical or similar queries\n\n**When to use**: Same queries asked repeatedly\n\nimport { createHash } from 'crypto';\nimport Redis from 'ioredis';\n\nconst redis = new Redis(process.env.REDIS_URL);\n\nclass ResponseCache {\n    private ttl = 3600;  \u002F\u002F 1 hour default\n\n    \u002F\u002F Exact match caching\n    async getCached(prompt: string): Promise\u003Cstring | null> {\n        const key = this.hashPrompt(prompt);\n        return await redis.get(`response:${key}`);\n    }\n\n    async setCached(prompt: string, response: string): Promise\u003Cvoid> {\n        const key = this.hashPrompt(prompt);\n        await redis.set(`response:${key}`, response, 'EX', this.ttl);\n    }\n\n    private hashPrompt(prompt: string): string {\n        return createHash('sha256').update(prompt).digest('hex');\n    }\n\n    \u002F\u002F Semantic similarity caching\n    async getSemanticallySimilar(\n        prompt: string,\n        threshold: number = 0.95\n    ): Promise\u003Cstring | null> {\n        const embedding = await embed(prompt);\n        const similar = await this.vectorCache.search(embedding, 1);\n\n        if (similar.length && similar[0].similarity > threshold) {\n            return await redis.get(`response:${similar[0].id}`);\n        }\n        return null;\n    }\n\n    \u002F\u002F Temperature-aware caching\n    async getCachedWithParams(\n        prompt: string,\n        params: { temperature: number; model: string }\n    ): Promise\u003Cstring | null> {\n        \u002F\u002F Only cache low-temperature responses\n        if (params.temperature > 0.5) return null;\n\n        const key = this.hashPrompt(\n            `${prompt}|${params.model}|${params.temperature}`\n        );\n        return await redis.get(`response:${key}`);\n    }\n}\n\n### Cache Augmented Generation (CAG)\n\nPre-cache documents in prompt instead of RAG retrieval\n\n**When to use**: Document corpus is stable and fits in context\n\n\u002F\u002F CAG: Pre-compute document context, cache in prompt\n\u002F\u002F Better than RAG when:\n\u002F\u002F - Documents are stable\n\u002F\u002F - Total fits in context window\n\u002F\u002F - Latency is critical\n\nclass CAGSystem {\n    private cachedContext: string | null = null;\n    private lastUpdate: number = 0;\n\n    async buildCachedContext(documents: Document[]): Promise\u003Cvoid> {\n        \u002F\u002F Pre-process and format documents\n        const formatted = documents.map(d =>\n            `## ${d.title}\\n${d.content}`\n        ).join('\\n\\n');\n\n        \u002F\u002F Store with timestamp\n        this.cachedContext = formatted;\n        this.lastUpdate = Date.now();\n    }\n\n    async query(userQuery: string): Promise\u003Cstring> {\n        \u002F\u002F Use cached context directly in prompt\n        const response = await client.messages.create({\n            model: \"claude-sonnet-4-20250514\",\n            max_tokens: 1024,\n            system: [\n                {\n                    type: \"text\",\n                    text: \"You are a helpful assistant with access to the following documentation.\",\n                    cache_control: { type: \"ephemeral\" }\n                },\n                {\n                    type: \"text\",\n                    text: this.cachedContext!,  \u002F\u002F Pre-cached docs\n                    cache_control: { type: \"ephemeral\" }\n                }\n            ],\n            messages: [{ role: \"user\", content: userQuery }]\n        });\n\n        return response.content[0].text;\n    }\n\n    \u002F\u002F Periodic refresh\n    async refreshIfNeeded(documents: Document[]): Promise\u003Cvoid> {\n        const stale = Date.now() - this.lastUpdate > 3600000;  \u002F\u002F 1 hour\n        if (stale) {\n            await this.buildCachedContext(documents);\n        }\n    }\n}\n\n\u002F\u002F CAG vs RAG decision matrix:\n\u002F\u002F | Factor           | CAG Better | RAG Better |\n\u002F\u002F |------------------|------------|------------|\n\u002F\u002F | Corpus size      | \u003C 100K tokens | > 100K tokens |\n\u002F\u002F | Update frequency | Low | High |\n\u002F\u002F | Latency needs    | Critical | Flexible |\n\u002F\u002F | Query specificity| General | Specific |\n\n## Sharp Edges\n\n### Cache miss causes latency spike with additional overhead\n\nSeverity: HIGH\n\nSituation: Slow response when cache miss, slower than no caching\n\nSymptoms:\n- Slow responses on cache miss\n- Cache hit rate below 50%\n- Higher latency than uncached\n\nWhy this breaks:\nCache check adds latency.\nCache write adds more latency.\nMiss + overhead > no caching.\n\nRecommended fix:\n\n\u002F\u002F Optimize for cache misses, not just hits\n\nclass OptimizedCache {\n    async queryWithCache(prompt: string): Promise\u003Cstring> {\n        const cacheKey = this.hash(prompt);\n\n        \u002F\u002F Non-blocking cache check\n        const cachedPromise = this.cache.get(cacheKey);\n        const llmPromise = this.queryLLM(prompt);\n\n        \u002F\u002F Race: use cache if available before LLM returns\n        const cached = await Promise.race([\n            cachedPromise,\n            sleep(50).then(() => null)  \u002F\u002F 50ms cache timeout\n        ]);\n\n        if (cached) {\n            \u002F\u002F Cancel LLM request if possible\n            return cached;\n        }\n\n        \u002F\u002F Cache miss: continue with LLM\n        const response = await llmPromise;\n\n        \u002F\u002F Async cache write (don't block response)\n        this.cache.set(cacheKey, response).catch(console.error);\n\n        return response;\n    }\n}\n\n\u002F\u002F Alternative: Probabilistic caching\n\u002F\u002F Only cache if query matches known high-frequency patterns\nclass SelectiveCache {\n    private patterns: Map\u003Cstring, number> = new Map();\n\n    shouldCache(prompt: string): boolean {\n        const pattern = this.extractPattern(prompt);\n        const frequency = this.patterns.get(pattern) || 0;\n\n        \u002F\u002F Only cache high-frequency patterns\n        return frequency > 10;\n    }\n\n    recordQuery(prompt: string): void {\n        const pattern = this.extractPattern(prompt);\n        this.patterns.set(pattern, (this.patterns.get(pattern) || 0) + 1);\n    }\n}\n\n### Cached responses become incorrect over time\n\nSeverity: HIGH\n\nSituation: Users get outdated or wrong information from cache\n\nSymptoms:\n- Users report wrong information\n- Answers don't match current data\n- Complaints about outdated responses\n\nWhy this breaks:\nSource data changed.\nNo cache invalidation.\nLong TTLs for dynamic data.\n\nRecommended fix:\n\n\u002F\u002F Implement proper cache invalidation\n\nclass InvalidatingCache {\n    \u002F\u002F Version-based invalidation\n    private cacheVersion = 1;\n\n    getCacheKey(prompt: string): string {\n        return `v${this.cacheVersion}:${this.hash(prompt)}`;\n    }\n\n    invalidateAll(): void {\n        this.cacheVersion++;\n        \u002F\u002F Old keys automatically become orphaned\n    }\n\n    \u002F\u002F Content-hash invalidation\n    async setWithContentHash(\n        key: string,\n        response: string,\n        sourceContent: string\n    ): Promise\u003Cvoid> {\n        const contentHash = this.hash(sourceContent);\n        await this.cache.set(key, {\n            response,\n            contentHash,\n            timestamp: Date.now()\n        });\n    }\n\n    async getIfValid(\n        key: string,\n        currentSourceContent: string\n    ): Promise\u003Cstring | null> {\n        const cached = await this.cache.get(key);\n        if (!cached) return null;\n\n        \u002F\u002F Check if source content changed\n        const currentHash = this.hash(currentSourceContent);\n        if (cached.contentHash !== currentHash) {\n            await this.cache.delete(key);\n            return null;\n        }\n\n        return cached.response;\n    }\n\n    \u002F\u002F Event-based invalidation\n    onSourceUpdate(sourceId: string): void {\n        \u002F\u002F Invalidate all caches that used this source\n        this.invalidateByTag(`source:${sourceId}`);\n    }\n}\n\n### Prompt caching doesn't work due to prefix changes\n\nSeverity: MEDIUM\n\nSituation: Cache misses despite similar prompts\n\nSymptoms:\n- Cache hit rate lower than expected\n- Cache creation tokens high, read low\n- Similar prompts not hitting cache\n\nWhy this breaks:\nAnthropic caching requires exact prefix match.\nTimestamps or dynamic content in prefix.\nDifferent message order.\n\nRecommended fix:\n\n\u002F\u002F Structure prompts for optimal caching\n\nclass CacheOptimizedPrompts {\n    \u002F\u002F WRONG: Dynamic content in cached prefix\n    buildPromptBad(query: string): SystemMessage[] {\n        return [\n            {\n                type: \"text\",\n                text: `You are helpful. Current time: ${new Date()}`,  \u002F\u002F BREAKS CACHE!\n                cache_control: { type: \"ephemeral\" }\n            }\n        ];\n    }\n\n    \u002F\u002F RIGHT: Static prefix, dynamic at end\n    buildPromptGood(query: string): SystemMessage[] {\n        return [\n            {\n                type: \"text\",\n                text: STATIC_SYSTEM_PROMPT,  \u002F\u002F Never changes\n                cache_control: { type: \"ephemeral\" }\n            },\n            {\n                type: \"text\",\n                text: STATIC_KNOWLEDGE_BASE,  \u002F\u002F Rarely changes\n                cache_control: { type: \"ephemeral\" }\n            }\n            \u002F\u002F Dynamic content goes in messages, NOT system\n        ];\n    }\n\n    \u002F\u002F Prefix ordering matters\n    buildWithConsistentOrder(components: string[]): SystemMessage[] {\n        \u002F\u002F Sort components for consistent ordering\n        const sorted = [...components].sort();\n        return sorted.map((c, i) => ({\n            type: \"text\",\n            text: c,\n            cache_control: i === sorted.length - 1\n                ? { type: \"ephemeral\" }\n                : undefined  \u002F\u002F Only cache the full prefix\n        }));\n    }\n}\n\n## Validation Checks\n\n### Caching High Temperature Responses\n\nSeverity: WARNING\n\nMessage: Caching with high temperature. Responses are non-deterministic.\n\nFix action: Only cache responses with temperature \u003C= 0.5\n\n### Cache Without TTL\n\nSeverity: WARNING\n\nMessage: Cache without TTL. May serve stale data indefinitely.\n\nFix action: Set appropriate TTL based on data freshness requirements\n\n### Dynamic Content in Cached Prefix\n\nSeverity: WARNING\n\nMessage: Dynamic content in cached prefix. Will cause cache misses.\n\nFix action: Move dynamic content outside of cache_control blocks\n\n### No Cache Metrics\n\nSeverity: INFO\n\nMessage: Cache without hit\u002Fmiss tracking. Can't measure effectiveness.\n\nFix action: Add cache hit\u002Fmiss metrics and logging\n\n## Collaboration\n\n### Delegation Triggers\n\n- context window|token -> context-window-management (Need context optimization)\n- rag|retrieval -> rag-implementation (Need retrieval system)\n- memory -> conversation-memory (Need memory persistence)\n\n### High-Performance LLM System\n\nSkills: prompt-caching, context-window-management, rag-implementation\n\nWorkflow:\n\n```\n1. Analyze query patterns\n2. Implement prompt caching for stable prefixes\n3. Add response caching for frequent queries\n4. Consider CAG for stable document sets\n5. Monitor and optimize hit rates\n```\n\n## Related Skills\n\nWorks well with: `context-window-management`, `rag-implementation`, `conversation-memory`\n\n## When to Use\n\n- User mentions or implies: prompt caching\n- User mentions or implies: cache prompt\n- User mentions or implies: response cache\n- User mentions or implies: cag\n- User mentions or implies: cache augmented\n",{"name":5,"risk":36,"source":37,"date_added":38,"description":7},"none","vibeship-spawner-skills (Apache 2.0)",1772150400000,"main","7a38d8e7073e61c16eda85681cb32fb68a8657a5","skills-store\u002Fglobal\u002Fprompt-caching","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router","https:\u002F\u002Fgithub.com\u002Fsapsapshen","2026-04-14 21:12:12",{"source":8,"skillName":5,"commands":46,"prompt":56,"zipAvailable":57},[47,50,53],{"tool":48,"command":49},"npx","npx skills add sapsapshen\u002Fai-memory-router --skill prompt-caching",{"tool":51,"command":52},"bunx","bunx skills add sapsapshen\u002Fai-memory-router --skill prompt-caching",{"tool":54,"command":55},"pnpm","pnpm dlx skills add sapsapshen\u002Fai-memory-router --skill prompt-caching","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fglobal\u002Fprompt-caching\u002FSKILL.md",true,[],[60,70,77,85,91,99],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":64,"licenseFileUrl":65,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":69},"01M72R8PZX1ABFHJGTYPA4CAF1","webapp-testing","To test local web applications, write native Python Playwright scripts.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fglobal\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fglobal\u002Fwebapp-testing\u002FSKILL.md",[],[],"2026-11-10 22:39:42",{"skillNo":71,"name":72,"nameZh":6,"description":73,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":69},"01M72QG37MMZNDY7X7GXPAK5W6","python-packaging","Comprehensive guide to creating, structuring, and distributing Python packages using modern packaging tools, pyproject.toml, and publishing to PyPI.","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fglobal\u002Fpython-packaging\u002FSKILL.md",[],[],{"skillNo":78,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":64,"licenseFileUrl":81,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":69},"01M72NXR0QMP9G46TW6A2DH59C","canvas-design","These are instructions for creating design philosophies - aesthetic movements that are then EXPRESSED VISUALLY. Output only .md files, .pdf files, and .png files.","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fglobal\u002Fcanvas-design\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fglobal\u002Fcanvas-design\u002FSKILL.md",[],[],{"skillNo":86,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":64,"licenseFileUrl":87,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":69},"01M72N55TK3EEQ4QK4AWDC2KZS","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcursor\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcursor\u002Fwebapp-testing\u002FSKILL.md",[],[],{"skillNo":92,"name":93,"nameZh":6,"description":94,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":64,"licenseFileUrl":95,"sourceHtmlUrl":96,"categories":97,"keywords":98,"publishedAt":69},"01M72MTWC150CFAP4Y5GSNKF80","slack-gif-creator","A toolkit providing utilities and knowledge for creating animated GIFs optimized for Slack.","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcursor\u002Fslack-gif-creator\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcursor\u002Fslack-gif-creator\u002FSKILL.md",[],[],{"skillNo":100,"name":101,"nameZh":6,"description":102,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":64,"licenseFileUrl":103,"sourceHtmlUrl":104,"categories":105,"keywords":106,"publishedAt":69},"01M72KPT3VVNSP88MNAY466TZT","frontend-design","You are a frontend designer-engineer, not a layout generator.","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcursor\u002Ffrontend-design\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcursor\u002Ffrontend-design\u002FSKILL.md",[],[]]