I5Intermediate 60 minutes reading and codeLocked

Prompt Caching and Context Caching

Your system prompt is 4,000 tokens. Your RAG context is 20,000 tokens. You send both with every request. You also pay for both — every time. Prompt caching lets the provider keep that prefix warm on their side and bill you 10% of the normal rate on reuse. Used correctly, it cuts inference cost by 50–90% and first-token latency by 40–85%.

In this lesson

  1. 01The Problem
  2. 02The Concept
  3. 03Build it
  4. 04Use it
  5. 05Exercises
  6. 06Key Terms
  7. 07Further Reading
  8. 08Pitfalls that still ship in 2026

About 1900 words of reading, with code, 5 quiz questions and the tutor.

The full lesson opens with an access code

You can see what this lesson covers and the milestone it sets. The full text, code, quizzes, the tutor and the AI reviews come with the K850 practice, along with weekly build sessions and code review.

Codes come with the K850 practice. Book a place

Milestone forA production labour-compliance assistant

Design for a high cache hit rate

Restructure the prompt so the contract and policies form a stable prefix, retrieved context follows, and the question comes last. Measure cache hit rate over a replay of 200 questions and find what breaks the prefix.

Done when

  • A stable-prefix prompt layout documented in the repo
  • Cache hit rate over a 200-question replay, at least 60%
  • One prefix-breaking cause found, fixed and re-measured

Stretch: Compare cost per query with and without caching

Reviews open with an access code.

Interview practice

Questions on this topic that AI engineering interviews ask, with the companies reported to ask them. Answer the way you would out loud; Jev scores it and DeepSeek tells you what to add.

Scoring opens with an access code. You can still read the questions and prepare.

Adapted from open-source work: AI Engineering from Scratch by Rohit Ghumare (MIT, lesson text, code and quizzes); Awesome LLM Apps by Shubham Saboo (Apache-2.0, starter code); AI Engineering Interview Questions by Outcome School (Apache-2.0, interview questions). Capstones, milestones, data packs and Zambian context by Zambrite.

Chat on WhatsApp