diff --git a/pkg/lru/cleanwork.go b/pkg/lru/cleanwork.go new file mode 100644 index 0000000..af787dc --- /dev/null +++ b/pkg/lru/cleanwork.go @@ -0,0 +1,28 @@ +package lru + +import ( + "context" + "gitee.com/timedb/wheatCache/pkg/event" + "gitee.com/timedb/wheatCache/pkg/proto" + "time" +) + +type cleanWorkSingle struct { + timeOut time.Duration + lru *SingleCache +} + +func (clean *cleanWorkSingle) cleanWork() (*proto.ReduceResponse, error) { + cxt := context.Background() + lruCleanEvent := event.NewEvent(CleanEventName) + lruCleanEvent.InitWaitEvent() + lruCleanEvent.SetValue(WorkFuncEventKey, clean.lru.DelToClearSize()) + clean.lru.lruCleanProduce.Call(cxt, lruCleanEvent) + resp, err := lruCleanEvent.StartWaitEvent(clean.timeOut) + if err != nil{ + return nil, err + } + return &proto.ReduceResponse{ + Result: resp.(string), + }, nil +} \ No newline at end of file diff --git a/pkg/lru/define.go b/pkg/lru/define.go index a5bb2ae..5198552 100644 --- a/pkg/lru/define.go +++ b/pkg/lru/define.go @@ -34,5 +34,4 @@ type CacheInterface interface { Add(key *proto.BaseKey, val structure.KeyBaseInterface) UpdateLruSize(length structure.UpdateLength) DelByKey(key *proto.BaseKey) error - DelToClearSize() error } diff --git a/pkg/lru/lru.go b/pkg/lru/lru.go index e109339..29a5ae7 100644 --- a/pkg/lru/lru.go +++ b/pkg/lru/lru.go @@ -78,7 +78,6 @@ func NewLRUCache() *SingleCache { } lruCache = lru go lru.lruSingleWork() - go lru.cleanWork() }) return lruCache }