mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-01 07:21:17 +00:00
37 lines
940 B
Go
37 lines
940 B
Go
package artwork
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"time"
|
|
|
|
"github.com/navidrome/navidrome/conf"
|
|
"github.com/navidrome/navidrome/consts"
|
|
"github.com/navidrome/navidrome/utils/cache"
|
|
"github.com/navidrome/navidrome/utils/singleton"
|
|
)
|
|
|
|
// artworkReader is the cache.Item the image cache loader dispatches on: Reader
|
|
// produces the (possibly resized) bytes to store under Key.
|
|
type artworkReader interface {
|
|
cache.Item
|
|
LastUpdated() time.Time
|
|
Reader(ctx context.Context) (io.ReadCloser, string, error)
|
|
}
|
|
|
|
type imageCache struct {
|
|
cache.FileCache
|
|
}
|
|
|
|
func GetImageCache() cache.FileCache {
|
|
return singleton.GetInstance(func() *imageCache {
|
|
return &imageCache{
|
|
FileCache: cache.NewFileCache("Image", conf.Server.ImageCacheSize, consts.ImageCacheDir, consts.DefaultImageCacheMaxItems,
|
|
func(ctx context.Context, arg cache.Item) (io.Reader, error) {
|
|
r, _, err := arg.(artworkReader).Reader(ctx)
|
|
return r, err
|
|
}),
|
|
}
|
|
})
|
|
}
|