본문으로 건너뛰기
Skillpedia
프롬프트 및 LLM48k · #5524

prompt-caching

하는 일

이 도구는 AI가 같은 내용을 반복해서 듣지 않아도 되도록 중요한 정보를 기억하게 돕습니다. 대화를 더 빠르고 저렴하게 만들어 줍니다.

사용하는 경우

  • ✓같은 질문을 여러 번 할 때.
  • ✓길고 반복적인 지시를 AI에게 내릴 때.
  • ✓AI가 자주 참고해야 하는 문서 묶음이 있을 때.

스킬 링크

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/prompt-caching/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/prompt-caching/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“요리 질문에 답하는 방법에 대한 제 지시를 기억해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

이 도구는 이전 답변이나 지시의 일부를 저장합니다. AI가 비슷한 질문을 받으면 모든 것을 다시 처리하지 않고 저장된 정보를 사용합니다.

기술 내용 (원본 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> {

…

자주 묻는 질문

'캐싱'이란 무엇인가요?

AI를 위한 단기 기억 같은 것입니다. 최근에 사용한 정보를 보관해 나중에 빠르게 꺼내 쓸 수 있게 합니다.

캐싱에는 어떤 종류가 있나요?

지시문(프롬프트), AI의 전체 응답, 미리 불러온 정보와 새 질문을 결합하는 방식이 있습니다.

모든 AI에서 작동하나요?

이 예시는 Claude나 OpenAI 같은 특정 모델에서 캐싱을 사용하는 방법에 초점을 둡니다. 하지만 캐싱의 원리는 많은 AI에 적용할 수 있습니다.

상세 정보

작성자의 원본 설명

Caching strategies for LLM prompts including Anthropic prompt caching, response caching, and CAG (Cache Augmented Generation)

repo: sickn33/agentic-awesome-skills

인기도

GitHub 스타
48k
순위
#5524
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬