feat(cache): TTL-aware cache tracker for batch workloads#61
Merged
Conversation
Add TTLTracker to pkg/cache. Monitors Anthropic's 5-minute prompt cache TTL per prefix hash and detects cold-start penalties. - Touch(prefixHash): records request, returns wasAlive (warm/cold) - NextDeadline / TimeUntilExpiry: time remaining before cache expires - ScheduleDeadline(hash, margin): latest safe time for next batch request - ExpiredEntries: all prefixes past their TTL deadline - Evict: remove entry on boundary retreat - Stats: aggregate alive/expired counts and hit/miss totals AnthropicCacheTTL constant (5m) exported for use by callers. Co-authored-by: Ona <[email protected]>
2f2a58b to
b73b59c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #49
What
Adds
TTLTrackertopkg/cache. Monitors Anthropic's 5-minute prompt cache TTL per prefix hash, detects cold-start penalties, and tells batch jobs the latest safe time to send the next request without letting the cache expire.Changes
pkg/cache/ttl.go(new)AnthropicCacheTTLconstant (5 minutes)TTLTracker: tracksTTLEntryper prefix hash behindsync.MutexTouch(prefixHash): records request, returnswasAlive(warm hit vs cold start); refreshesExpiresAton every callNextDeadline/TimeUntilExpiry: time remaining before cache expiresScheduleDeadline(hash, safetyMargin): latest safe time for next batch request (ExpiresAt - margin)ExpiredEntries(): all prefixes past their TTL deadlineEvict(hash): remove entry on boundary retreatStats(): aggregateAlivePrefixes,ExpiredPrefixes,TotalHits,TotalMissespkg/cache/ttl_test.go(new) — 9 testsUsage