Class GoogleGenAiCachedContentService

java.lang.Object
org.springframework.ai.google.genai.cache.GoogleGenAiCachedContentService

public class GoogleGenAiCachedContentService extends Object
Service for managing cached content in Google GenAI. Provides synchronous and asynchronous operations for creating, retrieving, updating, and deleting cached content.
Since:
1.1.0
Author:
Dan Dobrin
  • Constructor Details

    • GoogleGenAiCachedContentService

      public GoogleGenAiCachedContentService(com.google.genai.Client genAiClient)
  • Method Details

    • create

      Creates cached content from the given request.
      Parameters:
      request - the cached content creation request
      Returns:
      the created cached content
    • get

      @Nullable public GoogleGenAiCachedContent get(String name)
      Retrieves cached content by name.
      Parameters:
      name - the cached content name
      Returns:
      the cached content, or null if not found
    • update

      Updates cached content with new TTL or expiration.
      Parameters:
      name - the cached content name
      request - the update request
      Returns:
      the updated cached content
    • delete

      public boolean delete(String name)
      Deletes cached content by name.
      Parameters:
      name - the cached content name
      Returns:
      true if deleted successfully, false otherwise
    • list

      public GoogleGenAiCachedContentService.CachedContentPage list(@Nullable Integer pageSize, @Nullable String pageToken)
      Lists all cached content with optional pagination.
      Parameters:
      pageSize - the page size (null for default)
      pageToken - the page token for pagination (null for first page)
      Returns:
      list of cached content
    • listAll

      public List<GoogleGenAiCachedContent> listAll()
      Lists all cached content without pagination.
      Returns:
      list of all cached content
    • createAsync

      Asynchronously creates cached content from the given request.
      Parameters:
      request - the cached content creation request
      Returns:
      a future containing the created cached content
    • getAsync

      Asynchronously retrieves cached content by name.
      Parameters:
      name - the cached content name
      Returns:
      a future containing the cached content
    • updateAsync

      Asynchronously updates cached content with new TTL or expiration.
      Parameters:
      name - the cached content name
      request - the update request
      Returns:
      a future containing the updated cached content
    • deleteAsync

      public CompletableFuture<Boolean> deleteAsync(String name)
      Asynchronously deletes cached content by name.
      Parameters:
      name - the cached content name
      Returns:
      a future indicating success
    • extendTtl

      public GoogleGenAiCachedContent extendTtl(String name, Duration additionalTtl)
      Extends the TTL of cached content by the specified duration.
      Parameters:
      name - the cached content name
      additionalTtl - the additional TTL to add
      Returns:
      the updated cached content
    • refreshExpiration

      public GoogleGenAiCachedContent refreshExpiration(String name, Duration maxTtl)
      Refreshes the expiration of cached content to the maximum TTL.
      Parameters:
      name - the cached content name
      maxTtl - the maximum TTL to set
      Returns:
      the updated cached content
    • cleanupExpired

      public int cleanupExpired()
      Removes all expired cached content.
      Returns:
      the number of expired items removed