feat(lru): feat lru clean

This commit is contained in:
HuangJiaLuo 2021-10-05 19:28:53 +08:00
parent 54f80ae1f3
commit 0bcf214080
1 changed files with 25 additions and 23 deletions

View File

@ -6,6 +6,8 @@ import (
"gitee.com/timedb/wheatCache/pkg/errorx"
"gitee.com/timedb/wheatCache/pkg/event"
"gitee.com/timedb/wheatCache/pkg/structure"
"gitee.com/timedb/wheatCache/pkg/util"
"github.com/spf13/viper"
"sync/atomic"
)
@ -32,29 +34,29 @@ func (lru *SingleCache) UpdateLruSize(length structure.UpdateLength) {
}
func cacheInit() (int64, int64, int) {
//maxSize := viper.GetString("lruCache.maxSize")
//retMaxSize, maxErr := util.ParseSizeToBit(maxSize)
//if maxErr != nil {
// return 0, 0, 0
//}
//if retMaxSize == 0 {
// retMaxSize = lruMaxSize
//}
//
//clearSize := viper.GetString("lruCache.clearSize")
//retClearSize, clearErr := util.ParseSizeToBit(clearSize)
//if clearErr != nil {
// return 0, 0, 0
//}
//if retClearSize == 0 {
// retClearSize = lruClearSize
//}
//
//maxDriver := viper.GetInt("lruCache.eventDriverSize")
//if maxDriver == 0 {
// maxDriver = lruEventDriver
//}
return 30, 15, 2000
maxSize := viper.GetString("lruCache.maxSize")
retMaxSize, maxErr := util.ParseSizeToBit(maxSize)
if maxErr != nil {
return 0, 0, 0
}
if retMaxSize == 0 {
retMaxSize = lruMaxSize
}
clearSize := viper.GetString("lruCache.clearSize")
retClearSize, clearErr := util.ParseSizeToBit(clearSize)
if clearErr != nil {
return 0, 0, 0
}
if retClearSize == 0 {
retClearSize = lruClearSize
}
maxDriver := viper.GetInt("lruCache.eventDriverSize")
if maxDriver == 0 {
maxDriver = lruEventDriver
}
return retMaxSize, retClearSize, maxDriver
}
// NewLRUCache lru初始化