ContextCacheConfig
Configuration for context caching across all agents in an app.
When this config is present on an app, context caching is enabled for all agents. When absent (null), context caching is disabled.
Context caching can significantly reduce costs and improve response times by reusing previously processed context across multiple requests.
Constructing this type requires @OptIn(ExperimentalContextCachingFeature::class).
Constructors
Types
Fluent builder for ContextCacheConfig, provided primarily for Java callers. Any property left unset falls back to the same default as the constructor.
Properties
Maximum number of invocations to reuse the same cache before refreshing it. Must be in the range 1..100. Defaults to 10.
Optional HTTP options for the cache-creation call. Set this to add a timeout on CachedContent.create() calls (e.g. HttpOptions(timeout = 10.seconds)). When the cache creation call exceeds the timeout, it fails and the request proceeds without caching. null uses the model backend's default HTTP options.
Minimum prior-request tokens required to enable caching. This gates on the previous request's actual prompt token count (from the model's usage metadata), not an estimate of the current request. Gemini enforces a hard 4096-token minimum that always applies, so values below 4096 have no additional effect. No cache is created on the first request of a session; caching begins on the second turn once a previous token count is known. Context cache storage may have a cost, so set this higher to avoid caching small requests where the overhead may exceed the benefits. Must be non-negative. Defaults to 0.