feat(segcache): allow segment cache expiry of 0 to cache forever - #800
Merged
Conversation
The segment cache expiry could not be set to 0 to keep decoded segments forever. Two layers blocked it: the config slider was capped at min=1, and segcache.WithDefaults() silently rewrote any expiry <= 0 back to 24h, so even a 0 that reached the manager was clobbered. The cache engine itself already treats <= 0 as "never expire". Changes: - config: SegmentCacheConfig.ExpiryHours becomes *int so "unset" and "explicit 0" are distinguishable (mirrors the Enabled *bool idiom). Validate() normalizes nil -> 24h, preserving the default for unconfigured installs while an explicit 0 means "forever". - segcache: drop the ExpiryDuration default from WithDefaults(); the config layer now owns the default, so an explicit "forever" survives. - setup: dereference the pointer with a defensive nil guard. - serve: pointer-safe value comparison (intPtrValue) for the dynamic reload detection. - frontend: expiry slider min=0, renders "Forever" at 0, updated helper text and scale label. Behavior: nil (unset) -> 24h; explicit 0 -> forever (bounded by the size cap via LRU); N -> N hours.
3 tasks
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.
What & why
The segment cache expiry could not be set to 0 to keep decoded segments forever. Two layers blocked it:
min=1.segcache.WithDefaults()silently rewrote any expiry<= 0back to 24h — so even a 0 that reached the manager was clobbered.The cache engine itself (
SegmentCache.Cleanup) already treats<= 0as "never expire", so the intent existed but was blocked upstream.Changes
internal/config/manager.go):SegmentCacheConfig.ExpiryHoursbecomes*intso unset and explicit 0 are distinguishable (mirrors the existingEnabled *boolidiom).Validate()normalizesnil -> 24h, preserving the default for unconfigured installs while an explicit0means "forever".internal/nzbfilesystem/segcache/manager.go): drop theExpiryDurationdefault fromWithDefaults(); the config layer now owns the default, so an explicit "forever" survives.cmd/altmount/cmd/setup.go): dereference the pointer with a defensive nil guard.cmd/altmount/cmd/serve.go): pointer-safe value comparison (intPtrValue) for the dynamic reload detection.StreamingConfigSection.tsx): expiry slidermin=0, renders "Forever" at 0, updated helper text and scale label.Behavior
nil(unset)0NReviewer notes
*intpointer is the mechanism that distinguishes "never configured" from "explicitly 0";Validate()guarantees the frontend always receives a concrete number.<= 0, butEvict()still enforces the size cap, so "forever" is always bounded byMaxSizeGB.bun run check.Verification
go build ./...— cleango test ./internal/config/... ./internal/nzbfilesystem/segcache/...— passbun run check— pass