Class BedrockCacheOptions

java.lang.Object
org.springframework.ai.bedrock.converse.api.BedrockCacheOptions

public class BedrockCacheOptions extends Object
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:
  • Constructor Details

    • BedrockCacheOptions

      protected BedrockCacheOptions(@Nullable BedrockCacheStrategy strategy, boolean multiBlockSystemCaching)
    • BedrockCacheOptions

      protected BedrockCacheOptions(@Nullable BedrockCacheStrategy strategy, boolean multiBlockSystemCaching, @Nullable BedrockCacheTtl ttl)
  • Method Details

    • builder

      public static BedrockCacheOptions.Builder builder()
      Creates a new builder for constructing BedrockCacheOptions.
      Returns:
      a new Builder instance
    • getStrategy

      public BedrockCacheStrategy getStrategy()
      Gets the caching strategy.
      Returns:
      the configured BedrockCacheStrategy
    • isMultiBlockSystemCaching

      public boolean isMultiBlockSystemCaching()
      Returns whether multi-block system message caching is enabled. When enabled, each SystemMessage is emitted as a separate SystemContentBlock in the Bedrock Converse request, with a CachePoint placed 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:
      true if each system message is emitted as a separate content block with the cache point placed before the last block; false otherwise
    • getTtl

      public @Nullable BedrockCacheTtl getTtl()
      Gets the cache TTL.
      Returns:
      the configured BedrockCacheTtl, or null to apply Bedrock's default 5-minute TTL
      Since:
      2.0.1