ContextCacheConfig

data class ContextCacheConfig @ExperimentalContextCachingFeature constructor(val cacheIntervals: Int = 10, val ttl: ERROR CLASS: Symbol not found for Duration = 1800.seconds, val minTokens: Int = 0, val createHttpOptions: HttpOptions? = null)

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

Link copied to clipboard
constructor(cacheIntervals: Int = 10, ttl: ERROR CLASS: Symbol not found for Duration = 1800.seconds, minTokens: Int = 0, createHttpOptions: HttpOptions? = null)

Types

Link copied to clipboard

Fluent builder for ContextCacheConfig, provided primarily for Java callers. Any property left unset falls back to the same default as the constructor.

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Maximum number of invocations to reuse the same cache before refreshing it. Must be in the range 1..100. Defaults to 10.

Link copied to clipboard

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.

Link copied to clipboard

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.

Link copied to clipboard
val ttl: ERROR CLASS: Symbol not found for Duration

Time-to-live for the cache. Must be strictly positive. Defaults to 30 minutes.

Link copied to clipboard

Returns the TTL in the string format used for cache creation, e.g. "1800s".