feat: add a proper caching system to the transcoding functionality

This commit is contained in:
Deluan
2020-02-20 19:08:10 -05:00
parent fc14e346b9
commit a6b0c57ce0
9 changed files with 131 additions and 140 deletions
+18
View File
@@ -1,8 +1,14 @@
package engine
import (
"path/filepath"
"time"
"github.com/deluan/navidrome/conf"
"github.com/deluan/navidrome/consts"
"github.com/deluan/navidrome/engine/ffmpeg"
"github.com/google/wire"
"gopkg.in/djherbis/fscache.v0"
)
var Set = wire.NewSet(
@@ -17,4 +23,16 @@ var Set = wire.NewSet(
NewUsers,
NewMediaStreamer,
ffmpeg.New,
NewTranscodingCache,
)
func NewTranscodingCache() (fscache.Cache, error) {
lru := fscache.NewLRUHaunter(0, conf.Server.MaxTranscodingCacheSize, 30*time.Second)
h := fscache.NewLRUHaunterStrategy(lru)
cacheFolder := filepath.Join(conf.Server.DataFolder, consts.CacheDir)
fs, err := fscache.NewFs(cacheFolder, 0755)
if err != nil {
return nil, err
}
return fscache.NewCacheWithHaunter(fs, h)
}