feat(lru): update lru function
This commit is contained in:
parent
768f3df70e
commit
47a49b1fdb
|
@ -11,12 +11,6 @@ import (
|
|||
"sync/atomic"
|
||||
)
|
||||
|
||||
// feat
|
||||
/*
|
||||
1. cleanProduce
|
||||
2. 定义 LRUSingle Work 函数
|
||||
|
||||
*/
|
||||
|
||||
type keyBaseValue struct {
|
||||
key string
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package lru
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSingleCache_RetDriver(t *testing.T) {
|
||||
|
||||
}
|
|
@ -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 ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue