Skip to content

Cache proposal based on librespot-org logic#327

Open
palchrb wants to merge 2 commits into
devgianlu:masterfrom
palchrb:claude/go-librespot-cache-logic-iiq3po
Open

Cache proposal based on librespot-org logic#327
palchrb wants to merge 2 commits into
devgianlu:masterfrom
palchrb:claude/go-librespot-cache-logic-iiq3po

Conversation

@palchrb

@palchrb palchrb commented Jul 7, 2026

Copy link
Copy Markdown

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.

claude added 2 commits July 5, 2026 13:33
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
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