feat(lru): update lru event2

This commit is contained in:
bandl 2021-11-11 22:32:14 +08:00
parent 3f3b208db1
commit 3eb515325d
1 changed files with 8 additions and 7 deletions

View File

@ -7,6 +7,7 @@ import (
_ "gitee.com/wheat-os/wheatCache/conf" _ "gitee.com/wheat-os/wheatCache/conf"
"gitee.com/wheat-os/wheatCache/pkg/errorx" "gitee.com/wheat-os/wheatCache/pkg/errorx"
"gitee.com/wheat-os/wheatCache/pkg/event" "gitee.com/wheat-os/wheatCache/pkg/event"
"gitee.com/wheat-os/wheatCache/pkg/event2"
"gitee.com/wheat-os/wheatCache/pkg/middle" "gitee.com/wheat-os/wheatCache/pkg/middle"
"gitee.com/wheat-os/wheatCache/pkg/proto" "gitee.com/wheat-os/wheatCache/pkg/proto"
"gitee.com/wheat-os/wheatCache/pkg/structure" "gitee.com/wheat-os/wheatCache/pkg/structure"
@ -29,9 +30,9 @@ type SingleCache struct {
lruMaxDiverSize int lruMaxDiverSize int
lruTtlManage *lruTTl // 定时清理器 lruTtlManage *lruTTl // 定时清理器
lruDriver event.DriverInterface lruDriver event2.DriverInterface
lruConsumer event.ConsumerInterface lruConsumer event2.ConsumerInterface
lruCleanProduce event.ProduceInterface // 发送清理事件 lruCleanProduce event2.ProduceInterface // 发送清理事件
middleProduce event.ProduceInterface // 中间件驱动 middleProduce event.ProduceInterface // 中间件驱动
} }
@ -76,7 +77,7 @@ func cacheInit() (int64, int64, int, int) {
// NewLRUCache lru初始化 // NewLRUCache lru初始化
func NewLRUCache() *SingleCache { func NewLRUCache() *SingleCache {
maxSize, clearSize, maxDriverSize, detachNum := cacheInit() maxSize, clearSize, maxDriverSize, detachNum := cacheInit()
lruDriver := event.NewDriver(maxDriverSize) lruDriver := event2.NewDriver(maxDriverSize)
lruCacheOnce.Do(func() { lruCacheOnce.Do(func() {
lru := &SingleCache{ lru := &SingleCache{
maxsize: maxSize, maxsize: maxSize,
@ -86,8 +87,8 @@ func NewLRUCache() *SingleCache {
lruMap: make(map[string]*list.Element), lruMap: make(map[string]*list.Element),
lruMaxDiverSize: maxDriverSize, lruMaxDiverSize: maxDriverSize,
lruDriver: lruDriver, lruDriver: lruDriver,
lruConsumer: event.NewConsumer(lruDriver), lruConsumer: event2.NewConsumer(lruDriver),
lruCleanProduce: event.NewProduce(lruDriver), lruCleanProduce: event2.NewProduce(lruDriver),
middleProduce: event.NewProduce(middle.NewMiddleWare().GetEventDriver()), middleProduce: event.NewProduce(middle.NewMiddleWare().GetEventDriver()),
lruTtlManage: newLruTTl(detachNum), lruTtlManage: newLruTTl(detachNum),
} }
@ -103,7 +104,7 @@ func NewLRUCache() *SingleCache {
} }
// GetDriver 获取驱动 // GetDriver 获取驱动
func (lru *SingleCache) GetDriver() event.DriverInterface { func (lru *SingleCache) GetDriver() event2.DriverInterface {
return lru.lruDriver return lru.lruDriver
} }