From 61a21b0e0c271b0ee947d7aefd607ec959e740ed Mon Sep 17 00:00:00 2001 From: V1ck3s Date: Sun, 11 Jan 2026 00:24:29 +0100 Subject: [PATCH] refactor: centralize cache path logic and add TMPDIR documentation --- .env.example | 3 ++- octo-fiesta/Services/Common/BaseDownloadService.cs | 2 +- octo-fiesta/Services/Common/CacheCleanupService.cs | 2 +- octo-fiesta/Services/Common/PathHelper.cs | 11 +++++++++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index ffd4b06..6b2dd89 100644 --- a/.env.example +++ b/.env.example @@ -51,10 +51,11 @@ DOWNLOAD_MODE=Track # - Permanent: Files are saved to the library permanently and registered in Navidrome # - Cache: Files are stored in /tmp and automatically cleaned up after CACHE_DURATION_HOURS # Not registered in Navidrome, ideal for streaming without library bloat +# Note: On Linux/Docker, you can customize cache location by setting TMPDIR environment variable STORAGE_MODE=Permanent # Cache duration in hours (optional, default: 1) # Files older than this duration will be automatically deleted when STORAGE_MODE=Cache # Based on last access time (updated each time the file is streamed) -# Cache location: /tmp/octo-fiesta-cache (automatic, no configuration needed) +# Cache location: /tmp/octo-fiesta-cache (or $TMPDIR/octo-fiesta-cache if TMPDIR is set) CACHE_DURATION_HOURS=1 diff --git a/octo-fiesta/Services/Common/BaseDownloadService.cs b/octo-fiesta/Services/Common/BaseDownloadService.cs index 5709505..b41aaa2 100644 --- a/octo-fiesta/Services/Common/BaseDownloadService.cs +++ b/octo-fiesta/Services/Common/BaseDownloadService.cs @@ -47,7 +47,7 @@ public abstract class BaseDownloadService : IDownloadService Logger = logger; DownloadPath = configuration["Library:DownloadPath"] ?? "./downloads"; - CachePath = Path.Combine(Path.GetTempPath(), "octo-fiesta-cache"); + CachePath = PathHelper.GetCachePath(); if (!Directory.Exists(DownloadPath)) { diff --git a/octo-fiesta/Services/Common/CacheCleanupService.cs b/octo-fiesta/Services/Common/CacheCleanupService.cs index 13d7f0a..d49752b 100644 --- a/octo-fiesta/Services/Common/CacheCleanupService.cs +++ b/octo-fiesta/Services/Common/CacheCleanupService.cs @@ -61,7 +61,7 @@ public class CacheCleanupService : BackgroundService private async Task CleanupOldCachedFilesAsync(CancellationToken cancellationToken) { - var cachePath = Path.Combine(Path.GetTempPath(), "octo-fiesta-cache"); + var cachePath = PathHelper.GetCachePath(); if (!Directory.Exists(cachePath)) { diff --git a/octo-fiesta/Services/Common/PathHelper.cs b/octo-fiesta/Services/Common/PathHelper.cs index 93f43ad..94b226c 100644 --- a/octo-fiesta/Services/Common/PathHelper.cs +++ b/octo-fiesta/Services/Common/PathHelper.cs @@ -8,6 +8,17 @@ namespace octo_fiesta.Services.Common; /// public static class PathHelper { + /// + /// Gets the cache directory path for temporary file storage. + /// Uses system temp directory combined with octo-fiesta-cache subfolder. + /// Respects TMPDIR environment variable on Linux/macOS. + /// + /// Full path to the cache directory. + public static string GetCachePath() + { + return Path.Combine(Path.GetTempPath(), "octo-fiesta-cache"); + } + /// /// Builds the output path for a downloaded track following the Artist/Album/Track structure. ///