Add prompt-caching module: Spring AI 2.1 Anthropic cache strategies on the real request (breakpoints per strategy, hit/miss/write in Usage, one changed word, multi-block system caching, minimum length, 5-minute and 1-hour lifetimes, the 20-block lookback), OpenAI automatic caching with prompt_cache_key, and a cost table. The vendors are a local server applying their documented rules; no vendor API called. Spring Boot 4.2.0, Spring AI 2.1.0, Java 25.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b4gvXXQgw1eTk5EoTT
This commit is contained in:
Claude
2026-11-24 06:07:23 +05:30
parent 45d83826da
commit 02c3cbf439
32 changed files with 1759 additions and 0 deletions
@@ -0,0 +1,20 @@
# OpenAI through Spring AI 2.1.0: no breakpoints to place, where a message boundary falls, and a cached count in Usage
A. Same system prompt, different question (simulated rule: longest shared message-boundary prefix of at least 1,024 tokens)
request carried prompt_cache_key=support-assistant-v1 keys sent: [messages, model, prompt_cache_key]
call 1: getPromptTokens=6410 getCacheReadInputTokens=0 getCacheWriteInputTokens=null
call 2: getPromptTokens=6408 getCacheReadInputTokens=6080 getCacheWriteInputTokens=null
as a price-sheet bill: plain=328 read=6080 write=0
B. A clock inside the one big system message (the simulation caches whole messages, the GPT-5.6-and-later rule)
call 2: 0 of 6097 prompt tokens cached
C. The clock moved to its own message after the stable one, so a message boundary falls where the text starts to change
call 2: 6080 of 6097 prompt tokens cached
D. A prompt under 1,024 tokens (simulated minimum): no error, no caching
call 2: 0 of 635 prompt tokens cached
E. Options that exist in Spring AI 2.1.0, and one that has to travel through extraBody
keys on the wire: [messages, model, prompt_cache_key, prompt_cache_retention]
prompt_cache_retention=24h