C.W.K.
Stream
Lesson 06 of 10 · published

Context caching — 어떻게, 어디 쓸지

~18 min · context, caching, cost

Level 0수련생
0 XP0/100 lessons0/14 achievements
0/120 XP to next level120 XP to go0% complete

가장 큰 production cost lever

요즘 API는 프롬프트 일부를 cached로 mark 가능 — system 프롬프트, 긴 문서, tool catalog. Cache hit은 input cost의 일부로 billed (Anthropic: read 10%, write 25%, TTL 분~시간 범위). 같은 프롬프트 하루 1M번 부르는 시스템에 caching은 $60K/월 vs $6K/월 차이.

cache할 것

  • System 프롬프트 — tiny 아니면 거의 항상.
  • 거의 안 변하는 긴 문서 — manual, reference data.
  • Tool definition — schema와 description, 특히 many-tool agent에.
  • Few-shot example — example block 크고 stable하면.

cache 안 할 것

  • user의 현재 message.
  • per-request 데이터.
  • RAG 결과 (query마다 다름).

순서 trap

Cache breakpoint은 positional. breakpoint 전 모든 게 cache, 후 모든 게 fresh. 작은 system 프롬프트 + 큰 문서면 breakpoint를 문서 후에 set해. 프롬프트 reorder하면 cache invalidate. cache layout 한 번 결정, stable하게 유지.

Code

Anthropic prompt caching·python
client.messages.create(
    model="claude-opus-4-7",
    max_tokens=1024,
    system=[
        {
            "type": "text",
            "text": LARGE_REFERENCE_DOC,  # 50k tokens, rarely changes
            "cache_control": {"type": "ephemeral"}
        },
        {
            "type": "text",
            "text": "You are a contract analyst. ..."
        }
    ],
    messages=[{"role": "user", "content": user_question}]
)

External links

Exercise

stable하고 large한 prefix 있는 production 프롬프트 하나 식별. 거기 cache breakpoint 추가, 1,000 call에서 cost 변화 측정.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.