🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
feat: use human readable sizes in cache size configuration
Deluanc8cd75545102
diff --git a/conf/configuration.go b/conf/configuration.goindex c4202f409..9f9ad9993 100644--- a/conf/configuration.go+++ b/conf/configuration.go@@ -24,7 +24,7 @@ type nd struct {IgnoredArticles string `default:"The El La Los Las Le Les Os As O A"`IndexGroups string `default:"A B C D E F G H I J K L M N O P Q R S T U V W X-Z(XYZ) [Unknown]([)"`- TranscodingCacheSize int64 `default:"100"` // in MB+ TranscodingCacheSize string `default:"100MB"` // in MBProbeCommand string `default:"ffmpeg -i %s -f ffmetadata"`// DevFlags. These are used to enable/disable debugging and incomplete featuresdiff --git a/consts/consts.go b/consts/consts.goindex b85f9a016..416b566a1 100644--- a/consts/consts.go+++ b/consts/consts.go@@ -15,7 +15,10 @@ const (UIAssetsLocalPath = "ui/build"- CacheDir = "cache"+ CacheDir = "cache"+ DefaultTranscodingCacheSize = 100 * 1024 * 1024 // 100MB+ DefaultTranscodingCacheMaxItems = 0 // Unlimited+ DefaultTranscodingCachePurgeInterval = 10 * time.MinuteDevInitialUserName = "admin"DevInitialName = "Dev Admin"diff --git a/engine/media_streamer.go b/engine/media_streamer.goindex f9240a8d4..dfcf91bf3 100644--- a/engine/media_streamer.go+++ b/engine/media_streamer.go@@ -15,6 +15,7 @@ import ("github.com/deluan/navidrome/log""github.com/deluan/navidrome/model""github.com/djherbis/fscache"+ "github.com/dustin/go-humanize")type MediaStreamer interface {@@ -198,9 +199,15 @@ func getFinalCachedSize(r fscache.ReadAtCloser) int64 {}func NewTranscodingCache() (fscache.Cache, error) {- lru := fscache.NewLRUHaunter(0, conf.Server.TranscodingCacheSize*1024*1024, 10*time.Minute)+ cacheSize, err := humanize.ParseBytes(conf.Server.TranscodingCacheSize)+ if err != nil {+ cacheSize = consts.DefaultTranscodingCacheSize+ }+ lru := fscache.NewLRUHaunter(consts.DefaultTranscodingCacheMaxItems, int64(cacheSize), consts.DefaultTranscodingCachePurgeInterval)h := fscache.NewLRUHaunterStrategy(lru)cacheFolder := filepath.Join(conf.Server.DataFolder, consts.CacheDir)+ log.Info("Creating transcoding cache", "path", cacheFolder, "maxSize", humanize.Bytes(cacheSize),+ "cleanUpInterval", consts.DefaultTranscodingCachePurgeInterval)fs, err := fscache.NewFs(cacheFolder, 0755)if err != nil {return nil, errdiff --git a/go.mod b/go.modindex 2fb978638..80047e8f8 100644--- a/go.mod+++ b/go.mod@@ -11,6 +11,7 @@ require (github.com/dgrijalva/jwt-go v3.2.0+incompatiblegithub.com/dhowden/tag v0.0.0-20191122115059-7e5c04feccd8github.com/djherbis/fscache v0.10.0+ github.com/dustin/go-humanize v1.0.0github.com/fatih/camelcase v0.0.0-20160318181535-f6a740d52f96 // indirectgithub.com/fatih/structs v1.0.0 // indirectgithub.com/go-chi/chi v4.0.3+incompatiblediff --git a/go.sum b/go.sumindex 616f17708..e6829d16f 100644--- a/go.sum+++ b/go.sum@@ -30,6 +30,8 @@ github.com/dhowden/tag v0.0.0-20191122115059-7e5c04feccd8 h1:nmFnmD8VZXkjDHIb1Gngithub.com/dhowden/tag v0.0.0-20191122115059-7e5c04feccd8/go.mod h1:SniNVYuaD1jmdEEvi+7ywb1QFR7agjeTdGKyFb0p7Rw=github.com/djherbis/fscache v0.10.0 h1:+O3s3LwKL1Jfz7txRHpgKOz8/krh9w+NzfzxtFdbsQg=github.com/djherbis/fscache v0.10.0/go.mod h1:yyPYtkNnnPXsW+81lAcQS6yab3G2CRfnPLotBvtbf0c=+github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=+github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712 h1:aaQcKT9WumO6JEJcRyTqFVq4XUZiUcKR2/GI31TOcz8=github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=