Cache proposal based on librespot-org logic#327
Open
palchrb wants to merge 2 commits into
Open
Conversation
Port librespot's on-disk audio cache to go-librespot. Encrypted audio files downloaded from the CDN are stored on disk keyed by their Spotify file id (hex, two-character subdirectory), so replaying a track skips the storage-resolve and CDN download entirely. Only the still-encrypted bytes are stored, mirroring librespot: a cached file is useless without the audio key retrieved on every playback. The cache is enabled by default with a 1 GB size limit, after which the least-recently-used files are evicted. Configurable via cache.enabled, cache.dir and cache.size_limit. - new cache package: Cache (File/SaveFile, atomic writes) plus an LRU size limiter that reflects on-disk state across restarts - HttpChunkedReader gains an OnComplete hook that fires once every chunk is downloaded, used to persist the complete encrypted file - player.NewStream reads cache-first and saves on completion; the raw stream is closed if setup fails before hand-off Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FHWG4ossSBydy7jbVFWho
The size limiter seeds recency from file modification times on startup, so a purely in-memory touch meant the LRU order after a restart reflected write time rather than last access. Update the on-disk timestamps when a cached file is read, matching librespot's filetime-based touch. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FHWG4ossSBydy7jbVFWho
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.
Just leaving this here if you want it, apologies for messing up with some closed PRs already. It's just Claude-code based on using same logic of caching as in librespot-org.
Not extensively tested, but seems to work for me.