Class BedrockCacheOptions
java.lang.Object
org.springframework.ai.bedrock.converse.api.BedrockCacheOptions
AWS Bedrock cache options for configuring prompt caching behavior.
Prompt caching allows you to reduce latency and costs by reusing previously processed
prompt content. Cached content has a default 5-minute Time To Live (TTL) that resets
with each cache hit; a 1-hour TTL is also available via BedrockCacheTtl.
Example usage:
BedrockCacheOptions cacheOptions = BedrockCacheOptions.builder()
.strategy(BedrockCacheStrategy.SYSTEM_ONLY)
.build();
ChatResponse response = chatModel.call(new Prompt(
List.of(new SystemMessage(largeSystemPrompt), new UserMessage("Question")),
BedrockChatOptions.builder()
.cacheOptions(cacheOptions)
.build()
));
- Since:
- 1.1.0
- Author:
- Soby Chacko, Sebastien Deleuze
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for constructing BedrockCacheOptions instances. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBedrockCacheOptions(@Nullable BedrockCacheStrategy strategy, boolean multiBlockSystemCaching) protectedBedrockCacheOptions(@Nullable BedrockCacheStrategy strategy, boolean multiBlockSystemCaching, @Nullable BedrockCacheTtl ttl) -
Method Summary
Modifier and TypeMethodDescriptionstatic BedrockCacheOptions.Builderbuilder()Creates a new builder for constructing BedrockCacheOptions.Gets the caching strategy.@Nullable BedrockCacheTtlgetTtl()Gets the cache TTL.booleanReturns whether multi-block system message caching is enabled.
-
Constructor Details
-
BedrockCacheOptions
protected BedrockCacheOptions(@Nullable BedrockCacheStrategy strategy, boolean multiBlockSystemCaching) -
BedrockCacheOptions
protected BedrockCacheOptions(@Nullable BedrockCacheStrategy strategy, boolean multiBlockSystemCaching, @Nullable BedrockCacheTtl ttl)
-
-
Method Details
-
builder
Creates a new builder for constructing BedrockCacheOptions.- Returns:
- a new Builder instance
-
getStrategy
Gets the caching strategy.- Returns:
- the configured BedrockCacheStrategy
-
isMultiBlockSystemCaching
public boolean isMultiBlockSystemCaching()Returns whether multi-block system message caching is enabled. When enabled, eachSystemMessageis emitted as a separateSystemContentBlockin the Bedrock Converse request, with aCachePointplaced after the second-to-last text block. This allows a static system prompt prefix to be cached while dynamic content (e.g., advisor-injected RAG context) in the last block can change freely without invalidating the cache. When disabled (default), the cache point is placed after the last system block, so any change to the last block invalidates the cache.- Returns:
trueif each system message is emitted as a separate content block with the cache point placed before the last block;falseotherwise
-
getTtl
Gets the cache TTL.- Returns:
- the configured
BedrockCacheTtl, ornullto apply Bedrock's default 5-minute TTL - Since:
- 2.0.1
-