From 0bcf2140806d8fc82becaf3766a5b4fbd0af5230 Mon Sep 17 00:00:00 2001 From: HuangJiaLuo <1820799930@qq.com> Date: Tue, 5 Oct 2021 19:28:53 +0800 Subject: [PATCH] feat(lru): feat lru clean --- pkg/lru/lru.go | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/pkg/lru/lru.go b/pkg/lru/lru.go index 4dd6374..795c367 100644 --- a/pkg/lru/lru.go +++ b/pkg/lru/lru.go @@ -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初始化