Merge remote-tracking branch 'origin/add-Clear-Event' into add-Clear-Event

# Conflicts:
#	pkg/lru/define.go
#	pkg/lru/lru.go
This commit is contained in:
HuangJiaLuo 2021-10-11 19:06:48 +08:00
commit aebab3b3d7
3 changed files with 28 additions and 2 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
}

View File

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

View File

@ -78,7 +78,6 @@ func NewLRUCache() *SingleCache {
}
lruCache = lru
go lru.lruSingleWork()
go lru.cleanWork()
})
return lruCache
}