alist/bootstrap/cache.go

23 lines
590 B
Go
Raw Normal View History

2021-10-27 14:45:36 +00:00
package bootstrap
import (
"github.com/Xhofe/alist/conf"
"github.com/eko/gocache/v2/cache"
"github.com/eko/gocache/v2/store"
2021-10-28 14:50:09 +00:00
goCache "github.com/patrickmn/go-cache"
2021-10-27 14:45:36 +00:00
log "github.com/sirupsen/logrus"
"time"
)
// InitCache init cache
func InitCache() {
log.Infof("init cache...")
2021-12-30 12:42:37 +00:00
c := conf.Conf.Cache
if c.Expiration == 0 {
c.Expiration, c.CleanupInterval = 60, 120
}
goCacheClient := goCache.New(time.Duration(c.Expiration)*time.Minute, time.Duration(c.CleanupInterval)*time.Minute)
2021-10-28 14:50:09 +00:00
goCacheStore := store.NewGoCache(goCacheClient, nil)
conf.Cache = cache.New(goCacheStore)
}