
Gemini context caching reduces both cost and latency for prompts that repeatedly include the same large block of content, such as a long reference document or a detailed system instruction. On the Professional Machine Learning Engineer exam, scenarios with repeated prompt context focus on how caching changes request processing and when to choose between implicit caching, explicit caching, and custom expiration settings.
Without context caching, sending Gemini a prompt that contains a large block of reference material means the model processes every token of that block from scratch. When you send a second request with the same reference block, Gemini processes all of those tokens again, and a third request repeats the same work. Every request pays the full processing price for content that has not changed.
With context caching in place, the first request still pays the full cost because Gemini needs to read that content once. On the second, third, and subsequent requests, the cost drops sharply because the repeated portion is already stored and does not have to be processed from scratch each time. Those later requests mostly pay only for the new part of the prompt. Latency improves for the same reason, since there are fewer tokens to process before the model can begin generating a response.
Gemini provides two approaches to context caching, and the difference comes down to whether you want automatic handling or manual control over what is cached.
When a workload simply benefits from automatic reuse with no added setup, implicit caching handles it out of the box. When an application requires predictable reuse of specific reference material along with control over how long that material stays cached, we would lean toward explicit caching.
By default, an explicit cache expires after 60 minutes unless you specify a custom time to live (TTL). Once that hour ends, the cached content is dropped, and the next request that needs it pays the full processing cost again.
Setting a custom TTL keeps an explicit cache alive for as long as the workload requires. This is useful when the same reference material is reused across hours or days, such as a product manual or a policy document that many users query against.
Choosing a TTL involves balancing two competing costs, a trade-off that fits directly into Professional Machine Learning Engineer design questions. If you set the TTL too short, the cache expires prematurely and the application keeps repaying to reload the same content. If you set the TTL far longer than needed, you pay storage charges for a cache that requests are no longer hitting. As a practical rule, the TTL should roughly match how long the reference material stays relevant to your workload.
Our Professional Machine Learning Engineer course covers Gemini context caching alongside prompt design and generative AI inference optimization, with practice questions that drill these distinctions.