relay: own CacheTTLPolicy in pkg/relay instead of re-exporting registry's#22
Merged
Conversation
…ry's The public CacheTTLPolicy / CacheTTLInfinite were type/const aliases of the internal registry definitions, so the public API borrowed its own vocabulary from an implementation-detail package. Invert ownership: pkg/relay now defines CacheTTLPolicy and CacheTTLInfinite natively, and internal/registry keeps its own structurally-identical named type. relay converts to the registry type at the single construction-time boundary, so the dependency still points one way (registry never imports its parent) and neither layer passes a bare function signature. Drop the shared sentinel coupling while here: resolveCacheTTL now treats any negative duration as "disable time-based eviction" (d < 0) rather than comparing against a specific CacheTTLInfinite constant, so the registry no longer needs to know the public sentinel's value. Behavior is unchanged for every documented input. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Why
pkg/relay/cachettl.gore-exported the cache-TTL vocabulary from the internal registry:So the public API borrowed its own types from an implementation-detail package — the canonical definitions lived in
internal/registry, and the public surface was just an alias pointing inward.What
Ownership inverted.
pkg/relaynow definesCacheTTLPolicyandCacheTTLInfinitenatively (with the full contract doc).internal/registrykeeps its own structurally-identical named type, andrelayconverts at the single construction-time boundary:func(track.FullTrackName) time.Duration.Sentinel coupling dropped.
resolveCacheTTLnow treats any negative duration as "disable time-based eviction" (d < 0) instead of comparing against a specificCacheTTLInfiniteconstant, so the registry no longer needs to know the public sentinel's value.relay.CacheTTLInfinite = -1is just the canonical negative the public API blesses.Behavior is unchanged for every documented input (nil→default, negative→disabled, >0→that TTL, 0→default).
Test
go build ./...,go test ./pkg/relay/...,go vet, andgolangci-lint run ./pkg/relay/...all pass.🤖 Generated with Claude Code