remove gcache dependency, switch to custom image cache with TTL for memory savings

This commit is contained in:
Drew Weymouth
2023-02-02 15:52:59 -08:00
parent 0c06e13423
commit 867461dab5
7 changed files with 132 additions and 78 deletions
+2 -16
View File
@@ -4,7 +4,6 @@ import (
"log"
"strconv"
"github.com/bluele/gcache"
subsonic "github.com/dweymouth/go-subsonic"
)
@@ -15,15 +14,12 @@ type AlbumIterator interface {
type LibraryManager struct {
PreCacheCoverFn func(string)
s *ServerManager
albumDetailCache gcache.Cache
s *ServerManager
}
func NewLibraryManager(s *ServerManager) *LibraryManager {
cache := gcache.New(250).LRU().Build()
return &LibraryManager{
s: s,
albumDetailCache: cache,
s: s,
}
}
@@ -85,21 +81,11 @@ func (l *LibraryManager) SearchIterWithFilter(query string, filter func(*subsoni
return l.newSearchIter(query, filter)
}
func (l *LibraryManager) CacheAlbum(a *subsonic.AlbumID3) {
l.albumDetailCache.Set(a.ID, a)
}
func (l *LibraryManager) GetAlbum(id string) (*subsonic.AlbumID3, error) {
if l.albumDetailCache.Has(id) {
if a, err := l.albumDetailCache.Get(id); err == nil {
return a.(*subsonic.AlbumID3), nil
}
}
a, err := l.s.Server.GetAlbum(id)
if err != nil {
return nil, err
}
l.albumDetailCache.Set(a.ID, a)
return a, nil
}