When a generateContent request references an explicit cache using the Python SDK’s cached_content parameter, are the additional inline contents in that same request eligible for implicit cache hits?
Our test environment:
- API: Gemini Developer API
- Model:
gemini-3.5-flash - SDK: Python
google-genai==2.22.0
We compared two request patterns across repeated, interleaved rounds:
- Explicit cache reference: reference cached content A and send additional content B inline.
- Control: send A + B entirely inline, without referencing an explicit cache.
The explicit cache A contained 1,938 tokens. We tested B at two sizes: 7,698 and 86,738 tokens.
For requests referencing the explicit cache, cachedContentTokenCount consistently equaled 1,938, at both B sizes. For the larger B, the control request reported 85,984 cached tokens, demonstrating an implicit cache hit in the inline-only request pattern.
Our questions are:
- Is implicit cache lookup for the additional inline contents skipped when
cached_contentis set? - If explicit and implicit cache hits can occur in the same request, what conditions are required? Does
cachedContentTokenCountreport their combined token count? - Is this behavior the same on Vertex AI? Its context caching documentation states, “Explicit caches interact with implicit caching.” Does this interaction concern data retention only, or can it also produce combined cache hits in a single inference request?
Our primary question is whether both caching mechanisms can produce hits in the same inference request.