Revert "Make caches singletons"
This commit is contained in:
+1
-10
@@ -12,7 +12,6 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/deluan/navidrome/core/cache"
|
||||
@@ -206,14 +205,8 @@ func readFromFile(path string) ([]byte, error) {
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
var (
|
||||
onceImageCache sync.Once
|
||||
imageCache ArtworkCache
|
||||
)
|
||||
|
||||
func NewImageCache() ArtworkCache {
|
||||
onceImageCache.Do(func() {
|
||||
imageCache = cache.NewFileCache("Image", conf.Server.ImageCacheSize, consts.ImageCacheDir, consts.DefaultImageCacheMaxItems,
|
||||
return cache.NewFileCache("Image", conf.Server.ImageCacheSize, consts.ImageCacheDir, consts.DefaultImageCacheMaxItems,
|
||||
func(ctx context.Context, arg cache.Item) (io.Reader, error) {
|
||||
info := arg.(*imageInfo)
|
||||
reader, err := info.a.getArtwork(ctx, info.id, info.path, info.size)
|
||||
@@ -223,6 +216,4 @@ func NewImageCache() ArtworkCache {
|
||||
}
|
||||
return reader, nil
|
||||
})
|
||||
})
|
||||
return imageCache
|
||||
}
|
||||
|
||||
+1
-10
@@ -6,7 +6,6 @@ import (
|
||||
"io"
|
||||
"mime"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/deluan/navidrome/conf"
|
||||
@@ -168,14 +167,8 @@ func selectTranscodingOptions(ctx context.Context, ds model.DataStore, mf *model
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
onceTranscodingCache sync.Once
|
||||
transcodingCache TranscodingCache
|
||||
)
|
||||
|
||||
func NewTranscodingCache() TranscodingCache {
|
||||
onceTranscodingCache.Do(func() {
|
||||
transcodingCache = cache.NewFileCache("Transcoding", conf.Server.TranscodingCacheSize,
|
||||
return cache.NewFileCache("Transcoding", conf.Server.TranscodingCacheSize,
|
||||
consts.TranscodingCacheDir, consts.DefaultTranscodingCacheMaxItems,
|
||||
func(ctx context.Context, arg cache.Item) (io.Reader, error) {
|
||||
job := arg.(*streamJob)
|
||||
@@ -191,6 +184,4 @@ func NewTranscodingCache() TranscodingCache {
|
||||
}
|
||||
return out, nil
|
||||
})
|
||||
})
|
||||
return transcodingCache
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user