Class GoogleGenAiCachedContentService
java.lang.Object
org.springframework.ai.google.genai.cache.GoogleGenAiCachedContentService
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException thrown when cached content operations fail.static classResult of listing cached content with pagination support. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintRemoves all expired cached content.@Nullable GoogleGenAiCachedContentcreate(CachedContentRequest request) Creates cached content from the given request.createAsync(CachedContentRequest request) Asynchronously creates cached content from the given request.booleanDeletes cached content by name.deleteAsync(String name) Asynchronously deletes cached content by name.@Nullable GoogleGenAiCachedContentExtends the TTL of cached content by the specified duration.@Nullable GoogleGenAiCachedContentRetrieves cached content by name.Asynchronously retrieves cached content by name.Lists all cached content with optional pagination.listAll()Lists all cached content without pagination.@Nullable GoogleGenAiCachedContentrefreshExpiration(String name, Duration maxTtl) Refreshes the expiration of cached content to the maximum TTL.@Nullable GoogleGenAiCachedContentupdate(String name, CachedContentUpdateRequest request) Updates cached content with new TTL or expiration.updateAsync(String name, CachedContentUpdateRequest request) Asynchronously updates cached content with new TTL or expiration.
-
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
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 namerequest- the update request- Returns:
- the updated cached content
-
delete
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
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
public CompletableFuture<GoogleGenAiCachedContent> updateAsync(String name, CachedContentUpdateRequest request) Asynchronously updates cached content with new TTL or expiration.- Parameters:
name- the cached content namerequest- the update request- Returns:
- a future containing the updated cached content
-
deleteAsync
Asynchronously deletes cached content by name.- Parameters:
name- the cached content name- Returns:
- a future indicating success
-
extendTtl
Extends the TTL of cached content by the specified duration.- Parameters:
name- the cached content nameadditionalTtl- the additional TTL to add- Returns:
- the updated cached content
-
refreshExpiration
Refreshes the expiration of cached content to the maximum TTL.- Parameters:
name- the cached content namemaxTtl- 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
-