fix(server): memory leak in cache warmer (#4095)

* Prevent cache warmer memory leak when cache disabled

* refactor(tests): replace disabledCache with mockFileCache in CacheWarmer tests

Signed-off-by: Deluan <deluan@navidrome.org>

* test(cache): enhance CacheWarmer tests for initialization, buffer management, and error handling

Signed-off-by: Deluan <deluan@navidrome.org>

---------

Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Deluan Quintão
2025-05-21 21:48:49 -04:00
committed by GitHub
parent dd1d3907b4
commit 6731787053
4 changed files with 253 additions and 0 deletions
+10
View File
@@ -54,6 +54,9 @@ type FileCache interface {
// Available checks if the cache is available
Available(ctx context.Context) bool
// Disabled reports if the cache has been permanently disabled
Disabled(ctx context.Context) bool
}
// NewFileCache creates a new FileCache. This function initializes the cache and starts it in the background.
@@ -119,6 +122,13 @@ func (fc *fileCache) Available(_ context.Context) bool {
return fc.ready.Load() && !fc.disabled
}
func (fc *fileCache) Disabled(_ context.Context) bool {
fc.mutex.RLock()
defer fc.mutex.RUnlock()
return fc.disabled
}
func (fc *fileCache) invalidate(ctx context.Context, key string) error {
if !fc.Available(ctx) {
log.Debug(ctx, "Cache not initialized yet. Cannot invalidate key", "cache", fc.name, "key", key)