Skip to content

relay: own CacheTTLPolicy in pkg/relay instead of re-exporting registry's#22

Merged
floatdrop merged 1 commit into
draft-18from
relay-cachettl-ownership
Jun 26, 2026
Merged

relay: own CacheTTLPolicy in pkg/relay instead of re-exporting registry's#22
floatdrop merged 1 commit into
draft-18from
relay-cachettl-ownership

Conversation

@floatdrop

Copy link
Copy Markdown
Owner

Why

pkg/relay/cachettl.go re-exported the cache-TTL vocabulary from the internal registry:

type CacheTTLPolicy = registry.CacheTTLPolicy
const CacheTTLInfinite = registry.CacheTTLInfinite

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/relay now defines CacheTTLPolicy and CacheTTLInfinite natively (with the full contract doc). internal/registry keeps its own structurally-identical named type, and relay converts at the single construction-time boundary:

registry.WithCacheTTLPolicy(registry.CacheTTLPolicy(cfg.CacheTTLPolicy))
  • Dependency still points one way — registry never imports its parent.
  • Each layer has a named, self-documenting type — neither side passes a bare func(track.FullTrackName) time.Duration.

Sentinel coupling dropped. resolveCacheTTL now treats any negative duration as "disable time-based eviction" (d < 0) instead of comparing against a specific CacheTTLInfinite constant, so the registry no longer needs to know the public sentinel's value. relay.CacheTTLInfinite = -1 is 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, and golangci-lint run ./pkg/relay/... all pass.

🤖 Generated with Claude Code

…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>
@floatdrop floatdrop merged commit f39e422 into draft-18 Jun 26, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant