[PR #582] [MERGED] Refactor Cache and remove Volume struct #981

Closed
opened 2026-02-27 20:00:42 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/librespot-org/librespot/pull/582
Author: @Johannesd3
Created: 1/26/2021
Status: Merged
Merged: 2/2/2021
Merged by: @sashahilton00

Base: devHead: refactor_cache_remove_volume


📝 Commits (4)

📊 Changes

7 files changed (+159 additions, -155 deletions)

View changed files

📝 audio/src/fetch.rs (+1 -1)
📝 connect/src/spirc.rs (+1 -2)
📝 core/src/authentication.rs (+1 -28)
📝 core/src/cache.rs (+128 -78)
📝 core/src/lib.rs (+0 -1)
core/src/volume.rs (+0 -33)
📝 src/main.rs (+28 -12)

📄 Description

This PR suggest a refactor of Cache.

The Volume struct was removed, since its only purpose was to read and write a single integer in a file. Its logic was moved to Cache, as well as the functions to store Credentials to disk. It recently became possible to split audio and system cache (#506), so this PR makes the paths in struct Cache optional. Also, error handling and logging was improved. It contains some breaking changes.

Here are some random thoughts and questions about the cache I had while writing this PR. Some of this is stuff for future PRs.

  • The Cache feels now very "threefold". The struct could neatly be divided into three independent structs. It's basically twice the same code for volume and credentials, and even the code for audio files is similar. Is there any abstraction possible to avoid repetition?
  • Why are audio cache and "system cache" in a single struct anyway? The audio cache is only needed in the audio crate, and the system cache is mainly used in the connect crate and the application.
  • Would it be possible to use file-system-level copy to store audio files in cache? As far as I understand, the audio files are temporarily stored on disk.
  • The cache should use async file system operations (but this could happen in the tokio migration where it is much more convenient)
  • With #518, the audio cache is flushed whenever an error occurs. This should handle the case of a full disk, but it was not distinguished between "No space left" and other errors, and I'm not aware of how to check this in Rust platform-independently. (This functioniality is currently not present in this branch but could be added again.) In #34 and #558 was suggested to limit the cache size. Any smart solutions for these problems?

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/librespot-org/librespot/pull/582 **Author:** [@Johannesd3](https://github.com/Johannesd3) **Created:** 1/26/2021 **Status:** ✅ Merged **Merged:** 2/2/2021 **Merged by:** [@sashahilton00](https://github.com/sashahilton00) **Base:** `dev` ← **Head:** `refactor_cache_remove_volume` --- ### 📝 Commits (4) - [`14a004f`](https://github.com/librespot-org/librespot/commit/14a004f84c01642dcb8b5efce2fd20ac8fd45bfa) Refactored Cache - [`fa5c9f7`](https://github.com/librespot-org/librespot/commit/fa5c9f7d11367e6d298b11e4d4aaad26d5f21472) Made locations in cache optional - [`fd1f049`](https://github.com/librespot-org/librespot/commit/fd1f04957211c504491864a8fd8cf0fa324dd2f9) Removed volume struct - [`efedc67`](https://github.com/librespot-org/librespot/commit/efedc678d09e18e48f50e48f4f36070668a9fadc) Handle cache full situation ### 📊 Changes **7 files changed** (+159 additions, -155 deletions) <details> <summary>View changed files</summary> 📝 `audio/src/fetch.rs` (+1 -1) 📝 `connect/src/spirc.rs` (+1 -2) 📝 `core/src/authentication.rs` (+1 -28) 📝 `core/src/cache.rs` (+128 -78) 📝 `core/src/lib.rs` (+0 -1) ➖ `core/src/volume.rs` (+0 -33) 📝 `src/main.rs` (+28 -12) </details> ### 📄 Description This PR suggest a refactor of Cache. The `Volume` struct was removed, since its only purpose was to read and write a single integer in a file. Its logic was moved to `Cache`, as well as the functions to store `Credential`s to disk. It recently became possible to split audio and system cache (#506), so this PR makes the paths in `struct Cache` optional. Also, error handling and logging was improved. It contains some breaking changes. Here are some random thoughts and questions about the cache I had while writing this PR. Some of this is stuff for future PRs. * The `Cache` feels now very "threefold". The struct could neatly be divided into three independent structs. It's basically twice the same code for volume and credentials, and even the code for audio files is similar. Is there any abstraction possible to avoid repetition? * Why are audio cache and "system cache" in a single struct anyway? The audio cache is only needed in the audio crate, and the system cache is mainly used in the connect crate and the application. * Would it be possible to use file-system-level copy to store audio files in cache? As far as I understand, the audio files are temporarily stored on disk. * The cache should use async file system operations (but this could happen in the tokio migration where it is much more convenient) * With #518, the audio cache is flushed whenever an error occurs. This should handle the case of a full disk, but it was not distinguished between "No space left" and other errors, and I'm not aware of how to check this in Rust platform-independently. ~~(This functioniality is currently not present in this branch but could be added again.)~~ In #34 and #558 was suggested to limit the cache size. Any smart solutions for these problems? --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 20:00:42 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librespot#981
No description provided.