feat: add MaxAge and TTLRemaining to CandidateResponse#262
Merged
Conversation
Drop the deprecated CandidateResponse.TTL() call in the uncached candidate test; TTLRemaining() already covers it (age is 0, so remaining == full freshness lifetime). Fixes staticcheck SA1019. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
dgryski
requested changes
Jun 11, 2026
dgryski
left a comment
Member
There was a problem hiding this comment.
Minor suggested tweak, but otherwise LGTM.
Thanks!
| // rather than wrapping around. | ||
| func (candidateResponse *CandidateResponse) TTLRemaining() (uint32, error) { | ||
| var maxAge, age uint32 | ||
| if candidateResponse.useTTL { |
Member
There was a problem hiding this comment.
I think I'd prefer this if block to look like
opts, err := candidateResponse.getSuggestedCacheWriteOptions()
if err != nil {
return 0, err
}
maxAge, age = opts.maxAge, opts.age
if candidateResponse.useTTL {
maxAge = candidateResponse.overrideTTL
}
Contributor
Author
There was a problem hiding this comment.
Done in 00b3a4c. fsthttp tests pass locally.
Fetch the suggested cache write options once and override maxAge when a TTL is set, per review feedback.
Contributor
Author
|
Appreciate you landing this, @dgryski. Good to get MaxAge and TTLRemaining in and the ambiguous TTL deprecated. |
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.
Summary
Adds
MaxAge()andTTLRemaining()methods tofsthttp.CandidateResponseand deprecates the ambiguousTTL()method, bringing the Go SDK in line with the Rust SDK's cache-TTL surface.Why this matters (#250)
CandidateResponse.TTL()reportsmaxAge - age(the remaining freshness), but its name does not make clear whether it returns the full freshness lifetime of the cached object or the freshness left right now. The Rust SDK already deprecated itsTTLaccessor and split the concept intoMaxAge("how long the object stays fresh") andTTLRemaining("how much freshness is left right now"). This change mirrors that surface so callers can distinguish the two.Changes
MaxAge() (uint32, error)— returns the full suggested freshness lifetime (opts.maxAge, or the set TTL whenSetTTL/CacheOptions.TTLis in effect).TTLRemaining() (uint32, error)— returns the remaining freshness,maxAge - age, and saturates to0for already-stale candidates instead of wrapping the unsigned subtraction.TTL()is retained as a thin wrapper overTTLRemaining()and carries a// Deprecated:doc comment so existing callers keep working.getSuggestedCacheWriteOptions()result, so there is no ABI change.Testing
go test ./fsthttp/...passes.go vet ./...andgofmt -lare clean on the changed files.integration_tests/httpcachebuilds forGOOS=wasip1 GOARCH=wasm.testAfterSendCandidateResponsePropertiesUncachednow assertsMaxAge()returns the full suggested lifetime (3600) andTTLRemaining()returnsmaxAge - age, alongside the existingTTL()backward-compatibility assertion.Fixes #250