From 5fd93c33cb6dc89ce29c58b56510c684875b1b01 Mon Sep 17 00:00:00 2001 From: Henrik Friedrichsen Date: Fri, 7 May 2021 23:13:03 +0200 Subject: [PATCH] Add `audio_cache_size` to set maximum cache size --- README.md | 1 + src/config.rs | 1 + src/spotify.rs | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f2dbc47..ada64f3 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,7 @@ Possible configuration values are: * `backend_device`: Audio device string to configure the backend * `audio_cache`: Enable or disable caching of audio files, on by default +* `audio_cache_size`: Maximum size of audio cache in MiB * `volnorm`: Enable or disable volume normalization, off by default * `volnorm_pregain`: Normalization pregain to apply (if enabled) * `default_keybindings`: If disabled, the default keybindings are discarded, off diff --git a/src/config.rs b/src/config.rs index 3c32a8a..a56cef8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -21,6 +21,7 @@ pub struct ConfigValues { pub theme: Option, pub use_nerdfont: Option, pub audio_cache: Option, + pub audio_cache_size: Option, pub backend: Option, pub backend_device: Option, pub volnorm: Option, diff --git a/src/spotify.rs b/src/spotify.rs index 051ad52..c9c24f0 100644 --- a/src/spotify.rs +++ b/src/spotify.rs @@ -162,7 +162,9 @@ impl Spotify { let cache = Cache::new( Some(config::cache_path("librespot")), audio_cache_path, - None, + cfg.values() + .audio_cache_size + .map(|size| (size * 1048576) as u64), ) .expect("Could not create cache"); debug!("opening spotify session");