Add CACHE_ENABLED toggle to disable on-disk track cache#54
Open
Firestone82 wants to merge 1 commit into
Open
Conversation
…ache Cache the just-resolved audio in the background only after the streaming yt-dlp has had a few seconds of clean bandwidth, so the user hears playback start promptly instead of buffering against the parallel cache download. Add CACHE_ENABLED env var (default on) to turn the on-disk cache off entirely. When disabled, every play streams fresh from yt-dlp; !normalize becomes unavailable because it needs the cached file to measure loudness.
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 an optional
CACHE_ENABLEDenvironment variable to toggle the on-disk track cache at runtime. When disabled, tracks stream fresh from yt-dlp on every play, and loudness normalization is automatically unavailable since it requires a cached file to analyze.Changes
cache_service.rs: Added
is_enabled()function that reads theCACHE_ENABLEDenv var (defaults totrue). Updatedfind_cached()andcache_track()to return early when caching is disabled. Updatedis_cacheable()to also check the global cache state.player.rs: Modified
should_normalize()to returnfalsewhen caching is disabled, since loudness normalization needs an analyzable file path from the cache.player.rs (spawn_cache_and_apply): Added a 5-second delay before spawning the background cache task to give songbird's streaming yt-dlp a head-start and prevent network contention that would buffer playback.
cmd_normalize.rs: Added a guard that shows a
NormalizeUnavailableembed when users try!normalizewith caching disabled.player_embed.rs: Added
NormalizeUnavailablevariant to display an informative message explaining that normalization requires the cache to be enabled..env.example: Documented the new
CACHE_ENABLEDsetting with explanation of its behavior and relationship to!normalize.Implementation Details
is_enabled()function usesOnceLockto cache the env var lookup result, avoiding repeated parsing."0","false","no","off"disable;"1","true","yes","on"enable; empty string defaults to enabled.cache_track()returns anUnsupportedI/O error rather than silently succeeding.https://claude.ai/code/session_01DBbkH9JRpnAjM1C6Q4U2ed