Record Class ContextCacheConfig

java.lang.Object
java.lang.Record
com.google.adk.agents.ContextCacheConfig
Record Components:
cacheIntervals - maximum number of invocations that reuse the same cache before it is refreshed; must be from 1 to 100
ttl - time-to-live of the cache; must be a whole number of seconds, at least one
minTokens - minimum prompt token count of the agent's previous request needed to create a cache; raise it to skip small requests, where cache storage can cost more than it saves; must not be negative
createHttpOptions - HTTP options, such as a timeout, for the call that creates a cache, or null to use the client's defaults; if that call fails, the request is sent without a cache

public record ContextCacheConfig(int cacheIntervals, Duration ttl, int minTokens, @Nullable com.google.genai.types.HttpOptions createHttpOptions) extends Record
Configures context caching for all agents in an app. Without it, nothing is cached.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a config with the defaults: cacheIntervals of 10, ttl of 30 minutes, minTokens of 0, and the client's default HTTP options (createHttpOptions is null).
    ContextCacheConfig(int cacheIntervals, Duration ttl, int minTokens)
    Creates a config that creates caches with the client's default HTTP options.
    ContextCacheConfig(int cacheIntervals, Duration ttl, int minTokens, @Nullable com.google.genai.types.HttpOptions createHttpOptions)
    Creates a config.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the value of the cacheIntervals record component.
    @Nullable com.google.genai.types.HttpOptions
    Returns the value of the createHttpOptions record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    Returns the TTL in the "<seconds>s" form that the Gemini API uses.
    final int
    Returns a hash code value for this object.
    int
    Deprecated.
    Use cacheIntervals(), the name ADK Python and ADK Kotlin use.
    int
    Returns the value of the minTokens record component.
    Returns a string representation of this record class.
    ttl()
    Returns the value of the ttl record component.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ContextCacheConfig

      public ContextCacheConfig(int cacheIntervals, Duration ttl, int minTokens, @Nullable com.google.genai.types.HttpOptions createHttpOptions)
      Creates a config.
      Throws:
      IllegalArgumentException - if a value is out of range
    • ContextCacheConfig

      public ContextCacheConfig()
      Creates a config with the defaults: cacheIntervals of 10, ttl of 30 minutes, minTokens of 0, and the client's default HTTP options (createHttpOptions is null).
    • ContextCacheConfig

      public ContextCacheConfig(int cacheIntervals, Duration ttl, int minTokens)
      Creates a config that creates caches with the client's default HTTP options.
  • Method Details

    • maxInvocations

      @Deprecated @InlineMe(replacement="this.cacheIntervals()") public int maxInvocations()
      Deprecated.
      Use cacheIntervals(), the name ADK Python and ADK Kotlin use.
    • getTtlString

      public String getTtlString()
      Returns the TTL in the "<seconds>s" form that the Gemini API uses.
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • cacheIntervals

      public int cacheIntervals()
      Returns the value of the cacheIntervals record component.
      Returns:
      the value of the cacheIntervals record component
    • ttl

      public Duration ttl()
      Returns the value of the ttl record component.
      Returns:
      the value of the ttl record component
    • minTokens

      public int minTokens()
      Returns the value of the minTokens record component.
      Returns:
      the value of the minTokens record component
    • createHttpOptions

      public @Nullable com.google.genai.types.HttpOptions createHttpOptions()
      Returns the value of the createHttpOptions record component.
      Returns:
      the value of the createHttpOptions record component