mirror of
https://github.com/AlistGo/alist.git
synced 2025-04-22 21:04:07 +08:00
feat: set cache_expiration for each storage (close #1455)
This commit is contained in:
parent
5b40254e3b
commit
2e8322e99b
@ -31,16 +31,16 @@ type LogConfig struct {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Force bool `json:"force"`
|
||||
Address string `json:"address" env:"ADDR"`
|
||||
Port int `json:"port" env:"PORT"`
|
||||
JwtSecret string `json:"jwt_secret" env:"JWT_SECRET"`
|
||||
CaCheExpiration int `json:"cache_expiration" env:"CACHE_EXPIRATION"`
|
||||
Assets string `json:"assets" env:"ASSETS"`
|
||||
Database Database `json:"database"`
|
||||
Scheme Scheme `json:"scheme"`
|
||||
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
|
||||
Log LogConfig `json:"log"`
|
||||
Force bool `json:"force"`
|
||||
Address string `json:"address" env:"ADDR"`
|
||||
Port int `json:"port" env:"PORT"`
|
||||
JwtSecret string `json:"jwt_secret" env:"JWT_SECRET"`
|
||||
// CaCheExpiration int `json:"cache_expiration" env:"CACHE_EXPIRATION"`
|
||||
Assets string `json:"assets" env:"ASSETS"`
|
||||
Database Database `json:"database"`
|
||||
Scheme Scheme `json:"scheme"`
|
||||
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
|
||||
Log LogConfig `json:"log"`
|
||||
}
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
@ -56,7 +56,7 @@ func DefaultConfig() *Config {
|
||||
TablePrefix: "x_",
|
||||
DBFile: "data/data.db",
|
||||
},
|
||||
CaCheExpiration: 30,
|
||||
// CaCheExpiration: 30,
|
||||
Log: LogConfig{
|
||||
Enable: true,
|
||||
Path: "log/%Y-%m-%d-%H:%M.log",
|
||||
|
@ -3,14 +3,15 @@ package model
|
||||
import "time"
|
||||
|
||||
type Storage struct {
|
||||
ID uint `json:"id" gorm:"primaryKey"` // unique key
|
||||
MountPath string `json:"mount_path" gorm:"unique" binding:"required"` // must be standardized
|
||||
Index int `json:"index"` // use to sort
|
||||
Driver string `json:"driver"` // driver used
|
||||
Status string `json:"status"`
|
||||
Addition string `json:"addition" gorm:"type:text"` // Additional information, defined in the corresponding driver
|
||||
Remark string `json:"remark"`
|
||||
Modified time.Time `json:"modified"`
|
||||
ID uint `json:"id" gorm:"primaryKey"` // unique key
|
||||
MountPath string `json:"mount_path" gorm:"unique" binding:"required"` // must be standardized
|
||||
Index int `json:"index"` // use to sort
|
||||
Driver string `json:"driver"` // driver used
|
||||
CacheExpiration int `json:"cache_expiration"` // cache expire time
|
||||
Status string `json:"status"`
|
||||
Addition string `json:"addition" gorm:"type:text"` // Additional information, defined in the corresponding driver
|
||||
Remark string `json:"remark"`
|
||||
Modified time.Time `json:"modified"`
|
||||
Sort
|
||||
Proxy
|
||||
}
|
||||
|
@ -69,6 +69,15 @@ func getMainItems(config driver.Config) []driver.Item {
|
||||
Name: "down_proxy_url",
|
||||
Type: conf.TypeText,
|
||||
}}
|
||||
if !config.NoCache {
|
||||
items = append(items, driver.Item{
|
||||
Name: "cache_expiration",
|
||||
Type: conf.TypeNumber,
|
||||
Default: "30",
|
||||
Required: true,
|
||||
Help: "The cache expiration time for this storage",
|
||||
})
|
||||
}
|
||||
if !config.OnlyProxy && !config.OnlyLocal {
|
||||
items = append(items, []driver.Item{{
|
||||
Name: "web_proxy",
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/Xhofe/go-cache"
|
||||
"github.com/alist-org/alist/v3/internal/conf"
|
||||
"github.com/alist-org/alist/v3/internal/driver"
|
||||
"github.com/alist-org/alist/v3/internal/errs"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
@ -53,8 +52,7 @@ func List(ctx context.Context, storage driver.Driver, path string, refresh ...bo
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "failed to list files")
|
||||
}
|
||||
// TODO: maybe can get duration from storage's config
|
||||
filesCache.Set(key, files, cache.WithEx[[]model.Obj](time.Minute*time.Duration(conf.Conf.CaCheExpiration)))
|
||||
filesCache.Set(key, files, cache.WithEx[[]model.Obj](time.Minute*time.Duration(storage.GetStorage().CacheExpiration)))
|
||||
return files, nil
|
||||
})
|
||||
return files, err
|
||||
|
Loading…
x
Reference in New Issue
Block a user