feat(lru): update lru function

This commit is contained in:
HuangJiaLuo 2021-10-03 09:47:04 +08:00
parent 768f3df70e
commit 47a49b1fdb
3 changed files with 15 additions and 29 deletions

View File

@ -11,12 +11,6 @@ import (
"sync/atomic"
)
// feat
/*
1. cleanProduce
2. 定义 LRUSingle Work 函数
*/
type keyBaseValue struct {
key string

9
pkg/lru/woker_test.go Normal file
View File

@ -0,0 +1,9 @@
package lru
import (
"testing"
)
func TestSingleCache_RetDriver(t *testing.T) {
}

View File

@ -2,46 +2,29 @@ package lru
import (
"context"
"gitee.com/timedb/wheatCache/pkg/errorx"
"gitee.com/timedb/wheatCache/pkg/event"
"log"
"time"
)
func lruCleanWork() {
}
func funcWork(work SingleWorkFunc, ttl time.Duration) interface{} {
t := time.NewTimer(ttl)
resultCh := make(chan interface{})
go func() {
resultCh <- work()
}()
select {
case <-t.C:
return errorx.TimeOutErr()
case res := <-resultCh:
return res
}
}
func (lru *singleCache) lruSingleWork() interface{} {
ctx := context.Background()
for {
event := lru.lruConsumer.Receive(ctx)
eventKon := lru.lruConsumer.Receive(ctx)
worFunc, ok := event.GetValue(WorkFuncEventCtxKey)
worFunc, ok := eventKon.GetValue(WorkFuncEventCtxKey)
if !ok {
continue
}
switch worFunc.(type) {
case SingleWorkFunc:
_, err := event.ExecWorkAndSendResult(worFunc.(*event))
log.Println(err)
case event.EventWorkFunc:
eventKon.ExecWorkAndSendResult(worFunc.(event.EventWorkFunc))
default:
log.Print("this is debug ")
}
}
}