mirror of https://github.com/Xhofe/alist
🔧 Custom cache duration
parent
cf2506901f
commit
582f7bbfee
4
alist.go
4
alist.go
|
@ -48,8 +48,8 @@ func main() {
|
||||||
base := fmt.Sprintf("%s:%d", conf.Conf.Address, conf.Conf.Port)
|
base := fmt.Sprintf("%s:%d", conf.Conf.Address, conf.Conf.Port)
|
||||||
log.Infof("start server @ %s", base)
|
log.Infof("start server @ %s", base)
|
||||||
var err error
|
var err error
|
||||||
if conf.Conf.Https {
|
if conf.Conf.Scheme.Https {
|
||||||
err = r.RunTLS(base, conf.Conf.CertFile, conf.Conf.KeyFile)
|
err = r.RunTLS(base, conf.Conf.Scheme.CertFile, conf.Conf.Scheme.KeyFile)
|
||||||
} else {
|
} else {
|
||||||
err = r.Run(base)
|
err = r.Run(base)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,11 @@ import (
|
||||||
// InitCache init cache
|
// InitCache init cache
|
||||||
func InitCache() {
|
func InitCache() {
|
||||||
log.Infof("init cache...")
|
log.Infof("init cache...")
|
||||||
goCacheClient := goCache.New(60*time.Minute, 120*time.Minute)
|
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)
|
||||||
goCacheStore := store.NewGoCache(goCacheClient, nil)
|
goCacheStore := store.NewGoCache(goCacheClient, nil)
|
||||||
conf.Cache = cache.New(goCacheStore)
|
conf.Cache = cache.New(goCacheStore)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,14 +10,25 @@ type Database struct {
|
||||||
TablePrefix string `json:"table_prefix"`
|
TablePrefix string `json:"table_prefix"`
|
||||||
DBFile string `json:"db_file"`
|
DBFile string `json:"db_file"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Scheme struct {
|
||||||
|
Https bool `json:"https"`
|
||||||
|
CertFile string `json:"cert_file"`
|
||||||
|
KeyFile string `json:"key_file"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CacheConfig struct {
|
||||||
|
Expiration int64 `json:"expiration"`
|
||||||
|
CleanupInterval int64 `json:"cleanup_interval"`
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
Port int `json:"port"`
|
Port int `json:"port"`
|
||||||
Database Database `json:"database"`
|
Local bool `json:"local"`
|
||||||
Https bool `json:"https"`
|
Database Database `json:"database"`
|
||||||
CertFile string `json:"cert_file"`
|
Scheme Scheme `json:"scheme"`
|
||||||
KeyFile string `json:"key_file"`
|
Cache CacheConfig `json:"cache"`
|
||||||
Local bool `json:"local"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultConfig() *Config {
|
func DefaultConfig() *Config {
|
||||||
|
@ -30,5 +41,9 @@ func DefaultConfig() *Config {
|
||||||
TablePrefix: "x_",
|
TablePrefix: "x_",
|
||||||
DBFile: "data/data.db",
|
DBFile: "data/data.db",
|
||||||
},
|
},
|
||||||
|
Cache: CacheConfig{
|
||||||
|
Expiration: 60,
|
||||||
|
CleanupInterval: 120,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue