wheat-cache/storage/service/single.go

41 lines
889 B
Go

package service
import (
"time"
"gitee.com/timedb/wheatCache/pkg/event"
"gitee.com/timedb/wheatCache/pkg/lru"
"gitee.com/timedb/wheatCache/pkg/proto"
"gitee.com/timedb/wheatCache/storage/dao"
"github.com/spf13/viper"
)
type singleService struct {
middleProduce event.ProduceInterface
lruProduce event.ProduceInterface
timeOut time.Duration
lruCache *lru.SingleCache
dao dao.Interface
}
func NewSingleServer() proto.CommServerServer {
oneSingleServer.Do(func() {
timeOut := viper.GetInt("storage.timeOut")
if timeOut == 0 {
timeOut = timeOutDefault
}
lruCache := lru.NewLRUCache()
ser := &singleService{
lruCache: lruCache,
lruProduce: event.NewProduce(lruCache.GetDriver()),
timeOut: time.Duration(timeOut) * time.Second,
dao: dao.NewDao(lruCache),
}
sysSingleService = ser
})
return sysSingleService
}