feat(lru): feat the function of launching the cleanWorkFunc to driver

This commit is contained in:
HuangJiaLuo 2021-10-09 22:08:09 +08:00
parent 64b38044c8
commit 8a6db79fd6
1 changed files with 28 additions and 0 deletions

28
pkg/lru/cleanwork.go Normal file
View File

@ -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
}