cache

package
v0.10.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: GPL-3.0 Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cache implements an on-disk cache for the encrypted audio files downloaded from the Spotify CDN.

Only the raw, still-encrypted bytes are stored: a cached file is useless without a valid audio key retrieved per playback, mirroring the behaviour of the reference librespot implementation. Files are keyed by their Spotify file id and evicted least-recently-used once an optional size limit is reached.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache stores encrypted audio files on disk under <dir>/audio.

func New

func New(log librespot.Logger, dir string, sizeLimit int64) (*Cache, error)

New creates an audio file cache rooted at dir. When sizeLimit is greater than zero, least-recently-used files are evicted to keep the cache within the limit; a value of zero disables eviction (unbounded cache).

func (*Cache) File

func (c *Cache) File(fileId []byte) (librespot.SizedReadAtSeeker, bool)

File returns a reader for the cached encrypted audio file, if present. The boolean reports whether the file was found. Accessing a file refreshes its recency for LRU eviction.

func (*Cache) SaveFile

func (c *Cache) SaveFile(fileId []byte, r io.Reader) error

SaveFile stores the encrypted audio file identified by fileId, reading its contents from r. Writing is atomic: the data is written to a temporary file and renamed into place, so a crash never leaves a truncated cache entry. After a successful write, least-recently-used files are evicted when a size limit is configured.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL