Skip to content

Add CACHE_ENABLED toggle to disable on-disk track cache#54

Open
Firestone82 wants to merge 1 commit into
masterfrom
claude/stream-music-background-cache-P73s6
Open

Add CACHE_ENABLED toggle to disable on-disk track cache#54
Firestone82 wants to merge 1 commit into
masterfrom
claude/stream-music-background-cache-P73s6

Conversation

@Firestone82
Copy link
Copy Markdown
Owner

Summary

Adds an optional CACHE_ENABLED environment 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 the CACHE_ENABLED env var (defaults to true). Updated find_cached() and cache_track() to return early when caching is disabled. Updated is_cacheable() to also check the global cache state.

  • player.rs: Modified should_normalize() to return false when 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 NormalizeUnavailable embed when users try !normalize with caching disabled.

  • player_embed.rs: Added NormalizeUnavailable variant to display an informative message explaining that normalization requires the cache to be enabled.

  • .env.example: Documented the new CACHE_ENABLED setting with explanation of its behavior and relationship to !normalize.

Implementation Details

  • The is_enabled() function uses OnceLock to cache the env var lookup result, avoiding repeated parsing.
  • Accepts flexible boolean strings: "0", "false", "no", "off" disable; "1", "true", "yes", "on" enable; empty string defaults to enabled.
  • Invalid values log a warning and default to enabled for safety.
  • When caching is disabled, cache_track() returns an Unsupported I/O error rather than silently succeeding.

https://claude.ai/code/session_01DBbkH9JRpnAjM1C6Q4U2ed

…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.
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.

2 participants