diff --git a/core/artwork.go b/core/artwork.go index 3a7b771ce..8c89b3dd2 100644 --- a/core/artwork.go +++ b/core/artwork.go @@ -12,7 +12,6 @@ import ( "io" "os" "strings" - "sync" "time" "github.com/deluan/navidrome/core/cache" @@ -206,23 +205,15 @@ 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, - 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) - if err != nil { - log.Error(ctx, "Error loading artwork art", "path", info.path, "size", info.size, err) - return nil, err - } - return reader, nil - }) - }) - return imageCache + 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) + if err != nil { + log.Error(ctx, "Error loading artwork art", "path", info.path, "size", info.size, err) + return nil, err + } + return reader, nil + }) } diff --git a/core/media_streamer.go b/core/media_streamer.go index 499af3816..e3612400c 100644 --- a/core/media_streamer.go +++ b/core/media_streamer.go @@ -6,7 +6,6 @@ import ( "io" "mime" "os" - "sync" "time" "github.com/deluan/navidrome/conf" @@ -168,29 +167,21 @@ 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, - consts.TranscodingCacheDir, consts.DefaultTranscodingCacheMaxItems, - func(ctx context.Context, arg cache.Item) (io.Reader, error) { - job := arg.(*streamJob) - t, err := job.ms.ds.Transcoding(ctx).FindByFormat(job.format) - if err != nil { - log.Error(ctx, "Error loading transcoding command", "format", job.format, err) - return nil, os.ErrInvalid - } - out, err := job.ms.ffm.Start(ctx, t.Command, job.mf.Path, job.bitRate) - if err != nil { - log.Error(ctx, "Error starting transcoder", "id", job.mf.ID, err) - return nil, os.ErrInvalid - } - return out, nil - }) - }) - return transcodingCache + return cache.NewFileCache("Transcoding", conf.Server.TranscodingCacheSize, + consts.TranscodingCacheDir, consts.DefaultTranscodingCacheMaxItems, + func(ctx context.Context, arg cache.Item) (io.Reader, error) { + job := arg.(*streamJob) + t, err := job.ms.ds.Transcoding(ctx).FindByFormat(job.format) + if err != nil { + log.Error(ctx, "Error loading transcoding command", "format", job.format, err) + return nil, os.ErrInvalid + } + out, err := job.ms.ffm.Start(ctx, t.Command, job.mf.Path, job.bitRate) + if err != nil { + log.Error(ctx, "Error starting transcoder", "id", job.mf.ID, err) + return nil, os.ErrInvalid + } + return out, nil + }) }