prompt-caching
यह क्या करती है
यह टूल AI को ज़रूरी जानकारी याद रखने में मदद करता है, ताकि उसे बार-बार वही बात बतानी न पड़े। इससे बातचीत तेज़ और सस्ती होती है।
कब इस्तेमाल करें
- ✓जब आप एक ही सवाल कई बार पूछते हैं।
- ✓जब आप AI के लिए लंबे और बार-बार दोहराए जाने वाले निर्देश इस्तेमाल करते हैं।
- ✓जब आपके पास कुछ documents हैं जिन्हें AI को बार-बार देखना पड़ता है।
Skill का लिंक
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/prompt-caching/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“खाना बनाने के सवालों के जवाब देने के मेरे निर्देश याद रखो।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
टूल पिछले जवाब या निर्देशों के हिस्से स्टोर करता है। जब AI को कोई मिलता-जुलता सवाल मिलता है, तो वह सब कुछ दोबारा process करने के बजाय स्टोर की गई जानकारी का इस्तेमाल करता है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Prompt Caching
Caching strategies for LLM prompts including Anthropic prompt caching, response caching, and CAG (Cache Augmented Generation)
Capabilities
- prompt-cache
- response-cache
- kv-cache
- cag-patterns
- cache-invalidation
Prerequisites
- Knowledge: Caching fundamentals, LLM API usage, Hash functions
- Skills_recommended: context-window-management
Scope
- Does_not_cover: CDN caching, Database query caching, Static asset caching
- Boundaries: Focus is LLM-specific caching, Covers prompt and response caching
Ecosystem
Primary_tools
- Anthropic Prompt Caching - Native prompt caching in Claude API
- Redis - In-memory cache for responses (ioredis on servers; @upstash/redis over HTTP on serverless, see
upstash-redis) - OpenAI Caching - Automatic caching in OpenAI API
Patterns
Anthropic Prompt Caching
Use Claude's native prompt caching for repeated prefixes
When to use: Using Claude API with stable system prompts or context
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic();
// Cache the stable parts of your prompt async function queryWithCaching(userQuery: string) { const response = await client.messages.create({ model: "claude-sonnet-4-20250514", max_tokens: 1024, system: [ { type: "text", text: LONG_SYSTEM_PROMPT, // Your detailed instructions cache_control: { type: "ephemeral" } // Cache this! }, { type: "text", text: KNOWLEDGE_BASE, // Large static context cache_control: { type: "ephemeral" } } ], messages: [ { role: "user", content: userQuery } // Dynamic part ] });
// Check cache usage
console.log(`Cache read: ${response.usage.cache_read_input_tokens}`);
console.log(`Cache write: ${response.usage.cache_creation_input_tokens}`);
return response;
}
// Cost savings: 90% reduction on cached tokens // Latency savings: Up to 2x faster
Response Caching
Cache full LLM responses for identical or similar queries
When to use: Same queries asked repeatedly
import { createHash } from 'crypto'; import Redis from 'ioredis';
const redis = new Redis(process.env.REDIS_URL); // Serverless/edge alternative without a persistent connection: // import { Redis } from '@upstash/redis'; const redis = Redis.fromEnv(); // then use redis.set(key, value, { ex: ttl })
class ResponseCache { private ttl = 3600; // 1 hour default
// Exact match caching
async getCached(prompt: string): Promise<string | null> {
const key = this.hashPrompt(prompt);
return await redis.get(`response:${key}`);
}
async setCached(prompt: string, response: string): Promise<void> {
const key = this.hashPrompt(prompt);
await redis.set(`response:${key}`, response, 'EX', this.ttl);
}
private hashPrompt(prompt: string): string {
return createHash('sha256').update(prompt).digest('hex');
}
// Semantic similarity caching
async getSemanticallySimilar(
prompt: string,
threshold: number = 0.95
): Promise<string | null> {
const embedding = await embed(prompt);
const similar = await this.vectorCache.search(embedding, 1);
if (similar.length && similar[0].similarity > threshold) {
return await redis.get(`response:${similar[0].id}`);
}
return null;
}
// Temperature-aware caching
async getCachedWithParams(
prompt: string,
params: { temperature: number; model: string }
): Promise<string | null> {
// Only cache low-temperature responses
if (params.temperature > 0.5) return null;
const key = this.hashPrompt(
`${prompt}|${params.model}|${params.temperature}`
);
return await redis.get(`response:${key}`);
}
}
Cache Augmented Generation (CAG)
Pre-cache documents in prompt instead of RAG retrieval
When to use: Document corpus is stable and fits in context
// CAG: Pre-compute document context, cache in prompt // Better than RAG when: // - Documents are stable // - Total fits in context window // - Latency is critical
class CAGSystem { private cachedContext: string | null = null; private lastUpdate: number = 0;
async buildCachedContext(documents: Document[]): Promise<void> {
…
अक्सर पूछे जाने वाले सवाल
'caching' क्या है?
Caching AI के लिए short-term memory जैसा है। यह हाल में इस्तेमाल हुई जानकारी को संभालकर रखता है, ताकि बाद में उसे जल्दी निकाला जा सके।
caching के कौन-कौन से प्रकार हैं?
निर्देशों (prompts) के लिए, AI के पूरे जवाबों के लिए, और पहले से लोड की गई जानकारी को नए सवालों के साथ जोड़ने के लिए caching होती है।
क्या यह हर AI के साथ काम करता है?
यह उदाहरण Claude और OpenAI जैसे specific models के साथ caching के इस्तेमाल पर केंद्रित है, लेकिन caching का विचार कई AI पर लागू होता है।
जानकारी
लेखक का मूल विवरण
Caching strategies for LLM prompts including Anthropic prompt caching, response caching, and CAG (Cache Augmented Generation)
लोकप्रियता
- GitHub स्टार
- 48k
- रैंकिंग में स्थान
- #5524
- लाइसेंस
- MIT
- अपडेट की गई
- 15/10/2026
कमेंट
- …
इस repository की और skills
00-andruia-consultant
48kआपके एजेंट को AI प्रोजेक्ट शुरू करने या उन्हें बेहतर बनाने में मदद करता है। यह code का विश्लेषण करता है, tools सुझाता है और स्पेनिश भाषा में action plan बनाता है।
007
48kआपका एजेंट security audit और threat modeling करता है। यह प्रोजेक्ट को हमलों और कमजोरियों से बचाने में काम आता है।
10-andruia-skill-smith
48kआपके एजेंट को AI tools बनाने या उन्हें बेहतर करने में मदद करता है। यह तय करता है कि tools कैसे काम करेंगे, documentation लिखता है और structure की जांच करता है।
20-andruia-niche-intelligence
48kआपका एजेंट किसी खास industry का summary बनाता है। भरोसेमंद स्रोतों की मदद से यह प्रोजेक्ट का संदर्भ, नियम, इस्तेमाल के तरीके और जोखिम समझने में मदद करता है।
मिलती-जुलती skills
writing-skills
311kयह आपके एजेंट को नई स्किल लिखना और हर एक को पहले टेस्ट करना सिखाती है, यह जांचते हुए कि स्किल सच में उसका व्यवहार बदलती है।
writing-for-agents
310kAI एजेंट्स के लिए साफ़ निर्देश कैसे लिखें, यह समझाती है, जिसमें स्किल, AGENTS.md और CLAUDE.md फ़ाइलें शामिल हैं, ताकि एजेंट अनुमानित ढंग से व्यवहार करे।
bengali-nlp
280kयह आपके एजेंट को Bengali text प्रोसेस करने देता है। यह भाषा को समझने और उसके text को normalize करने जैसी उसकी खास बातों को संभालने में मदद करता है।