alist/drivers/base/cache.go

29 lines
769 B
Go
Raw Normal View History

package base
import (
"fmt"
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils"
2021-12-10 14:24:43 +00:00
log "github.com/sirupsen/logrus"
)
func KeyCache(path string, account *model.Account) string {
path = utils.ParsePath(path)
return fmt.Sprintf("%s%s", account.Name, path)
}
func SetCache(path string, obj interface{}, account *model.Account) error {
return conf.Cache.Set(conf.Ctx, KeyCache(path, account), obj, nil)
}
func GetCache(path string, account *model.Account) (interface{}, error) {
2021-12-08 14:44:45 +00:00
return conf.Cache.Get(conf.Ctx, KeyCache(path, account))
}
func DeleteCache(path string, account *model.Account) error {
2021-12-10 14:24:43 +00:00
err := conf.Cache.Delete(conf.Ctx, KeyCache(path, account))
log.Debugf("delete cache %s: %+v", path, err)
return err
}