[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7C32Y5EXJK0ZXW2NME4TM1K":3,"skill-same:01M7C32Y5EXJK0ZXW2NME4TM1K":50},{"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":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":27,"commitSha":28,"skillDirectory":29,"forksCount":30,"repositoryHtmlUrl":31,"repositoryHomepageUrl":32,"ownerHtmlUrl":33,"ownerBlogUrl":6,"ownerDescription":34,"updatedAt":35,"install":36,"resources":49},"01M7C32Y5EXJK0ZXW2NME4TM1K","prompt-caching",null,"Caching strategies for LLM prompts including Anthropic prompt caching, response caching, and CAG (Cache Augmented Generation)","YYC-Cube\u002FYYC3-Knowledge-Base","YYC-Cube","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F235006543?v=4","01M79J2PH4SWD2X0825X6PN748","yyc3","01M79J2PHVK3F6ZBYT8K2SCZCW",1,"MIT","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-Skills-技能包\u002FYYC3-Skills-技能包-antigravity-awesome-skills\u002Fplugins\u002Fantigravity-awesome-skills-claude\u002Fskills\u002Fprompt-caching\u002FSKILL.md",[],[],"2026-11-15 14:19:17",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- 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\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\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- 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\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n",{"name":5,"risk":24,"source":25,"date_added":26,"description":7},"none","vibeship-spawner-skills (Apache 2.0)",1772150400000,"main","87afe6ce96220accf50a345dea46784c8c9f210e","YYC3-Skills-技能包\u002FYYC3-Skills-技能包-antigravity-awesome-skills\u002Fplugins\u002Fantigravity-awesome-skills-claude\u002Fskills\u002Fprompt-caching",0,"https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base","https:\u002F\u002Fkb.yyc3.top\u002F","https:\u002F\u002Fgithub.com\u002FYYC-Cube","万象归元于云枢 | 深栈智启新纪元","2026-11-10 10:37:32",{"source":8,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill prompt-caching",{"tool":42,"command":43},"bunx","bunx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill prompt-caching",{"tool":45,"command":46},"pnpm","pnpm dlx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill prompt-caching","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-Skills-技能包\u002FYYC3-Skills-技能包-antigravity-awesome-skills\u002Fplugins\u002Fantigravity-awesome-skills-claude\u002Fskills\u002Fprompt-caching\u002FSKILL.md",true,[],[51,58,65,72,79,86],{"skillNo":52,"name":53,"nameZh":6,"description":54,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":55,"categories":56,"keywords":57,"publishedAt":19},"01M7CTDWHERCXPQCP0K03A86AS","vercel-sandbox","Run agent-browser + Chrome inside Vercel Sandbox microVMs for browser automation from any Vercel-deployed app. Use when the user needs browser automation in a Vercel app (Next.js, SvelteKit, Nuxt, Remix, Astro, etc.), wants to run headless Chrome without binary size limits, needs persistent browser sessions across commands, or wants ephemeral isolated browser environments. Triggers include \"Vercel Sandbox browser\", \"microVM Chrome\", \"agent-browser in sandbox\", \"browser automation on Vercel\", or any task requiring Chrome in a Vercel Sandbox.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fvercel-sandbox\u002FSKILL.md",[],[],{"skillNo":59,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"publishedAt":19},"01M7CTD8D2BNJY54S65M47HEJA","slack","Interact with Slack workspaces using browser automation. Use when the user needs to check unread channels, navigate Slack, send messages, extract data, find information, search conversations, or automate any Slack task. Triggers include \"check my Slack\", \"what channels have unreads\", \"send a message to\", \"search Slack for\", \"extract from Slack\", \"find who said\", or any task requiring programmatic Slack interaction.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fslack\u002FSKILL.md",[],[],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":19},"01M7CTCSSB8ZP3Q58C3YZDZK1W","electron","Automate Electron desktop apps (VS Code, Slack, Discord, Figma, Notion, Spotify, etc.) using agent-browser via Chrome DevTools Protocol. Use when the user needs to interact with an Electron app, automate a desktop app, connect to a running app, control a native app, or test an Electron application. Triggers include \"automate Slack app\", \"control VS Code\", \"interact with Discord app\", \"test this Electron app\", \"connect to desktop app\", or any task requiring automation of a native Electron application.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Felectron\u002FSKILL.md",[],[],{"skillNo":73,"name":74,"nameZh":6,"description":75,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":19},"01M7CTCBJY76688V4DCZGWFHGQ","dogfood","Systematically explore and test a web application to find bugs, UX issues, and other problems. Use when asked to \"dogfood\", \"QA\", \"exploratory test\", \"find issues\", \"bug hunt\", \"test this app\u002Fsite\u002Fplatform\", or review the quality of a web application. Produces a structured report with full reproduction evidence -- step-by-step screenshots, repro videos, and detailed repro steps for every issue -- so findings can be handed directly to the responsible teams.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fdogfood\u002FSKILL.md",[],[],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":19},"01M7CTC4H0FFGVEAQR9PA4GA1A","agent-browser","Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to \"open a website\", \"fill out a form\", \"click a button\", \"take a screenshot\", \"scrape data from a page\", \"test this web app\", \"login to a site\", \"automate browser actions\", or any task requiring programmatic web interaction.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fagent-browser\u002FSKILL.md",[],[],{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":19},"01M7CTBKVFYBG78FDSABSDJTTQ","shadcn","Manages shadcn components and projects — adding, searching, fixing, debugging, styling, and composing UI, including chat interfaces. Provides project context, component docs, and usage examples. Applies when working with shadcn\u002Fui, component registries, presets, --preset codes, or any project with a components.json file. Also triggers for \"shadcn init\", \"create an app with --preset\", \"switch to --preset\", and for building a design system or applying a DESIGN.md or brand spec to shadcn\u002Fui.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-UI-界面组件\u002FYYC3-UI-界面组件-ui\u002Fskills\u002Fshadcn\u002FSKILL.md",[],[]]