C.W.K.
Stream
Lesson 05 of 05 · published

Cache 산수: Worked Example

~24 min · cost, math, savings

Level 0Window Watcher
0 XP0/50 lessons0/13 achievements
0/100 XP to next level100 XP to go0% complete

숫자가 case 만든다

Caching 논리는 실제 워크플로 산수 하면 즉시 명백. 50K-token codebase review가 8K-token feedback 만드는 게 illustrative Sonnet pricing($3/M input, $15/M output, $0.30/M cached input)에서 본다.

세 시나리오

시나리오 A — single shot: 50K input × $3/M + 8K output × $15/M = $0.27.

시나리오 B — 10 follow-up turn, no caching: history 매 turn 자라 (~50K → ~100K), input 지배 → ~$3.50 input + ~$1.20 output = ~$4.70.

시나리오 C — 10 follow-up turn, caching: 안정적 prefix(~45K) cached, fresh input ~5K per turn → ~$0.40 input + ~$1.20 output = ~$1.60. 같은 대화, 3배 저렴.

Caching 가장 빨리 payback되는 곳

큰 stable prefix(rules + tool schemas + corpus), 많은 short follow-up turn, short variable tail 워크플로. Coding agent, customer-support bot, long research chat이 canonical 승리. Single-shot one-off prompt는 거의 이득 X.

Code

Cache 산수 estimator·python
def estimate(prefix_tokens, tail_tokens, output_tokens, turns,
             p_input=3.0, p_cached=0.30, p_output=15.0):
    # All prices per million tokens.
    no_cache = (prefix_tokens + tail_tokens) * turns / 1e6 * p_input \
             + output_tokens * turns / 1e6 * p_output
    with_cache = (prefix_tokens / 1e6 * p_input                     # first turn full price
                 + prefix_tokens * (turns - 1) / 1e6 * p_cached     # next turns cached
                 + tail_tokens * turns / 1e6 * p_input              # tail always fresh
                 + output_tokens * turns / 1e6 * p_output)
    return {"no_cache": round(no_cache, 2), "with_cache": round(with_cache, 2)}
Sample run·python
estimate(prefix_tokens=45_000, tail_tokens=5_000,
         output_tokens=2_000, turns=10)
# -> { "no_cache": 1.80, "with_cache": 0.61 }  (illustrative)

External links

Exercise

실제 long-running AI 워크플로 골라. 현실적 prefix/tail/output token count + turn count를 estimator에 plug. With/without caching cost 계산. Cache 구조 투자할지 결정.
Hint
Cached cost가 no-cache보다 30%+ 낮으면, caching은 사실상 공돈.

Progress

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

댓글 0

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

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