Enum Class AnthropicCacheStrategy
- All Implemented Interfaces:
Serializable, Comparable<AnthropicCacheStrategy>, Constable
- Since:
- 1.1.0
- Author:
- Mark Pollack, Soby Chacko
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionCache the entire conversation history up to (but not including) the current user question.No caching (default behavior).Cache system instructions and tool definitions.Cache system instructions only.Cache tool definitions only. -
Method Summary
Modifier and TypeMethodDescriptionstatic AnthropicCacheStrategyReturns the enum constant of this class with the specified name.static AnthropicCacheStrategy[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
NONE
No caching (default behavior). All content is processed fresh on each request.Use this when:
- Requests are one-off or highly variable
- Content doesn't meet minimum token requirements (1024+ tokens)
- You want to avoid caching overhead
-
TOOLS_ONLY
Cache tool definitions only. Places a cache breakpoint on the last tool, while system messages and conversation history remain uncached and are processed fresh on each request.Use this when:
- Tool definitions are large and stable (5000+ tokens)
- System prompts change frequently or are small (<500 tokens)
- You want to share cached tools across different system contexts (e.g., multi-tenant applications, A/B testing system prompts)
- Tool definitions rarely change
Important: Changing any tool definition will invalidate this cache entry. Due to Anthropic's cascade invalidation, tool changes will also invalidate any downstream cache breakpoints (system, messages) if used in combination with other strategies.
-
SYSTEM_ONLY
Cache system instructions only. Places a cache breakpoint on the system message content. Tools are cached implicitly via Anthropic's automatic ~20-block lookback mechanism (content before the cache breakpoint is included in the cache).Use this when:
- System prompts are large and stable (1024+ tokens)
- Tool definitions are relatively small (<20 tools)
- You want simple, single-breakpoint caching
Note: Changing tools will invalidate the cache since tools are part of the cache prefix (they appear before system in the request hierarchy).
-
SYSTEM_AND_TOOLS
Cache system instructions and tool definitions. Places cache breakpoints on the last tool (breakpoint 1) and system message content (breakpoint 2).Use this when:
- Both tools and system prompts are large and stable
- You have many tools (20+ tools, beyond the automatic lookback window)
- You want deterministic, explicit caching of both components
- System prompts may change independently of tools
Behavior:
- If only tools change: Both caches invalidated (tools + system)
- If only system changes: Tools cache remains valid, system cache invalidated
-
CONVERSATION_HISTORY
Cache the entire conversation history up to (but not including) the current user question. Places a cache breakpoint on the last user message in the conversation history, enabling incremental caching as the conversation grows.Use this when:
- Building multi-turn conversational applications (chatbots, assistants)
- Conversation history is large and grows over time
- You want to reuse conversation context while asking new questions
- Using chat memory advisors or conversation persistence
Behavior: Each turn builds on the previous cached prefix. The cache grows incrementally: Request 1 caches [Message1], Request 2 caches [Message1 + Message2], etc. This provides significant cost savings (90%+) and performance improvements for long conversations.
Important: Changing tools or system prompts will invalidate the entire conversation cache due to cascade invalidation. Tool and system stability is critical for this strategy.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-