Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose librespots support for limiting the cache size #1092

Merged
merged 2 commits into from
Jul 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/src/config/File.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ bitrate = 160
# shell placeholders like $HOME or ~ don't work!
cache_path = "cache_directory"

# The maximal size of the cache directory in bytes
# The example value corresponds to ~ 1GB
max_cache_size = 1000000000

# If set to true, audio data does NOT get cached.
no_audio_cache = true

Expand Down
11 changes: 9 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ pub struct SharedConfigValues {
#[structopt(long, parse(from_os_str), short, value_name = "string")]
cache_path: Option<PathBuf>,

/// The maximal cache size in bytes
#[structopt(long)]
max_cache_size: Option<u64>,

/// Disable the use of audio cache
#[structopt(long)]
#[serde(default)]
Expand Down Expand Up @@ -459,6 +463,7 @@ impl fmt::Debug for SharedConfigValues {
.field("proxy", &self.proxy)
.field("device_type", &self.device_type)
.field("autoplay", &self.autoplay)
.field("max_cache_size", &self.max_cache_size)
.finish()
}
}
Expand Down Expand Up @@ -521,7 +526,8 @@ impl SharedConfigValues {
zeroconf_port,
proxy,
device_type,
use_mpris
use_mpris,
max_cache_size
);

// Handles boolean merging.
Expand Down Expand Up @@ -580,6 +586,7 @@ pub(crate) struct SpotifydConfig {
pub(crate) fn get_internal_config(config: CliConfig) -> SpotifydConfig {
let audio_cache = !config.shared_config.no_audio_cache;

let size_limit = config.shared_config.max_cache_size;
let cache = config
.shared_config
.cache_path
Expand All @@ -590,7 +597,7 @@ pub(crate) fn get_internal_config(config: CliConfig) -> SpotifydConfig {
Cache::new(
Some(path.clone()),
if audio_cache { Some(path) } else { None },
None,
size_limit,
)
.ok()
});
Expand Down