wheat-cache/storage/server/single/single.go

41 lines
873 B
Go
Raw Normal View History

2021-10-05 16:41:17 +08:00
package single
import (
2021-10-20 21:35:56 +08:00
"time"
2021-10-05 16:41:17 +08:00
"gitee.com/timedb/wheatCache/pkg/event"
"gitee.com/timedb/wheatCache/pkg/lru"
2021-10-20 21:35:56 +08:00
"gitee.com/timedb/wheatCache/pkg/proto"
2021-10-05 16:41:17 +08:00
"gitee.com/timedb/wheatCache/storage/dao"
"github.com/spf13/viper"
)
type serverSingle struct {
middleProduce event.ProduceInterface
lruProduce event.ProduceInterface
timeOut time.Duration
lruCache *lru.SingleCache
dao *dao.Dao
}
2021-10-20 21:35:56 +08:00
func NewServer() proto.CommServerServer {
2021-10-05 16:41:17 +08:00
oneSingleServer.Do(func() {
timeOut := viper.GetInt("storage.timeOut")
if timeOut == 0 {
timeOut = timeOutDefault
}
lruCache := lru.NewLRUCache()
ser := &serverSingle{
lruCache: lruCache,
lruProduce: event.NewProduce(lruCache.GetDriver()),
2021-10-06 16:51:06 +08:00
timeOut: time.Duration(timeOut) * time.Second,
2021-10-05 16:41:17 +08:00
dao: dao.NewDao(lruCache),
}
sysSingleServer = ser
})
return sysSingleServer
}