mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-23 18:49:21 +08:00
feat: 增加定时清理缓存 (#5226)
This commit is contained in:
parent
90bcf464d3
commit
d38d2c617d
@ -46,6 +46,9 @@ func Run() {
|
||||
if _, err := global.Cron.AddJob(fmt.Sprintf("%v %v * * *", mathRand.Intn(60), mathRand.Intn(3)), job.NewAppStoreJob()); err != nil {
|
||||
global.LOG.Errorf("can not add appstore corn job: %s", err.Error())
|
||||
}
|
||||
if _, err := global.Cron.AddJob("@daily", job.NewCacheJob()); err != nil {
|
||||
global.LOG.Errorf("can not add cache corn job: %s", err.Error())
|
||||
}
|
||||
|
||||
var backup model.BackupAccount
|
||||
_ = global.DB.Where("type = ?", "OneDrive").Find(&backup).Error
|
||||
|
26
backend/cron/job/cache.go
Normal file
26
backend/cron/job/cache.go
Normal file
@ -0,0 +1,26 @@
|
||||
package job
|
||||
|
||||
import (
|
||||
"github.com/1Panel-dev/1Panel/backend/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Cache struct{}
|
||||
|
||||
func NewCacheJob() *Cache {
|
||||
return &Cache{}
|
||||
}
|
||||
|
||||
func (c *Cache) Run() {
|
||||
global.LOG.Info("run cache gc start ...")
|
||||
ticker := time.NewTicker(5 * time.Minute)
|
||||
defer ticker.Stop()
|
||||
for range ticker.C {
|
||||
again:
|
||||
err := global.CacheDb.RunValueLogGC(0.7)
|
||||
if err == nil {
|
||||
goto again
|
||||
}
|
||||
}
|
||||
global.LOG.Info("run cache gc end ...")
|
||||
}
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/1Panel-dev/1Panel/backend/configs"
|
||||
"github.com/1Panel-dev/1Panel/backend/init/cache/badger_db"
|
||||
"github.com/1Panel-dev/1Panel/backend/init/session/psession"
|
||||
"github.com/dgraph-io/badger/v4"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"github.com/robfig/cron/v3"
|
||||
@ -20,6 +21,7 @@ var (
|
||||
VALID *validator.Validate
|
||||
SESSION *psession.PSession
|
||||
CACHE *badger_db.Cache
|
||||
CacheDb *badger.DB
|
||||
Viper *viper.Viper
|
||||
|
||||
Cron *cron.Cron
|
||||
|
3
backend/init/cache/cache.go
vendored
3
backend/init/cache/cache.go
vendored
@ -49,7 +49,8 @@ func Init() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_ = cache.DropAll()
|
||||
global.CacheDb = cache
|
||||
global.CACHE = badger_db.NewCacheDB(cache)
|
||||
global.LOG.Info("init cache successfully")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user