CacheMetadata

data class CacheMetadata(val fingerprint: String, val contentsCount: Int, val cacheName: String? = null, val expireTime: Long? = null, val invocationsUsed: Int? = null, val createdAt: Long? = null)

Metadata for the context cache associated with LLM responses.

This stores cache identification, usage tracking, and lifecycle information for a particular cache instance. It can be in one of two states:

  1. Active cache state: cacheName is set and expireTime, invocationsUsed, and createdAt are populated.

  2. Fingerprint-only state: cacheName is null and only fingerprint and contentsCount are set, used for prefix matching before a cache exists.

Token counts (cached and total) are available in LlmResponse.usageMetadata and should be accessed from there to avoid duplication.

Constructors

Link copied to clipboard
constructor(fingerprint: String, contentsCount: Int, cacheName: String? = null, expireTime: Long? = null, invocationsUsed: Int? = null, createdAt: Long? = null)

Types

Link copied to clipboard
class Builder

Fluent builder for CacheMetadata, 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

Full resource name of the cached content (e.g. projects/123/locations/us-central1/cachedContents/456). null when no active cache exists.

Link copied to clipboard

Number of contents. When an active cache exists this is the count of cached contents; otherwise it is the count of the cacheable content prefix used for fingerprinting. Must be non-negative.

Link copied to clipboard

Epoch milliseconds when the cache was created. null when no active cache exists.

Link copied to clipboard

Whether the cache will expire within EXPIRY_BUFFER. Always false for fingerprint-only metadata (which has no expireTime).

Link copied to clipboard

Epoch milliseconds when the cache expires. null when no active cache exists.

Link copied to clipboard

Hash of the cacheable contents (system instruction + tools + contents). Always present for prefix matching.

Link copied to clipboard

Number of invocations this cache has been used for. null when no active cache exists. Must be non-negative when set.

Link copied to clipboard

Whether this metadata refers to an active cache, as opposed to a fingerprint-only state.

Functions

Link copied to clipboard
open override fun toString(): String