wheat-cache/pkg/lru/define.go

35 lines
701 B
Go
Raw Normal View History

2021-09-21 19:28:14 +08:00
package lru
2021-09-27 11:29:47 +08:00
2021-10-05 16:53:16 +08:00
import (
"gitee.com/timedb/wheatCache/pkg/proto"
2021-10-05 16:53:16 +08:00
"gitee.com/timedb/wheatCache/pkg/structure"
"sync"
)
2021-10-04 16:25:09 +08:00
2021-09-27 11:29:47 +08:00
type SingleWorkFunc func() interface{}
const (
2021-10-04 20:32:20 +08:00
OptionEventName = "operateEvent"
2021-10-05 16:53:16 +08:00
CleanEventName = "clearEvent"
2021-10-04 16:25:09 +08:00
WorkFuncEventKey = "workFunc"
)
2021-09-27 11:29:47 +08:00
2021-10-04 16:25:09 +08:00
var (
lruCacheOnce sync.Once
2021-10-05 16:53:16 +08:00
lruCache *SingleCache
2021-09-27 11:29:47 +08:00
)
2021-10-04 20:32:20 +08:00
const (
2021-10-05 16:53:16 +08:00
lruMaxSize = 1 * 1024 * 1024 * 1024 * 8
lruClearSize = 0.5 * 1024 * 1024 * 1024 * 8
2021-10-04 20:32:20 +08:00
lruEventDriver = 2000
)
2021-10-05 16:53:16 +08:00
type CacheInterface interface {
Del() error
Get(key *proto.BaseKey) (structure.KeyBaseInterface, bool)
Add(key *proto.BaseKey, val structure.KeyBaseInterface)
2021-10-05 16:53:16 +08:00
UpdateLruSize(length structure.UpdateLength)
DelByKey(key *proto.BaseKey) error
}