Package com.tnsai.llm.cache
Class CacheControl
java.lang.Object
com.tnsai.llm.cache.CacheControl
Cache control configuration for prompt caching.
CacheControl is used to mark content for caching in LLM requests. Currently supports Anthropic's ephemeral caching strategy.
Anthropic Prompt Caching
Anthropic allows caching of:
- System prompts
- Tool definitions
- Conversation history (up to last 4 cache breakpoints)
Cost Benefits
- Cache writes: 25% more expensive than base input tokens
- Cache reads: 90% cheaper than base input tokens
- TTL: 5 minutes (refreshed on each use)
Usage Example
// Mark system prompt for caching
CacheablePrompt cachedSystem = CacheablePrompt.of(
"You are an expert assistant...",
CacheControl.ephemeral()
);
// Use in chat
client.chat(message, cachedSystem);
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic CacheControlCreates an ephemeral cache control.getType()Gets the cache control type.Gets the type value as string.toString()
-
Method Details