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

39 lines
808 B
Go
Raw Permalink Normal View History

2021-10-05 16:41:17 +08:00
package single
import (
"gitee.com/timedb/wheatCache/pkg/event"
"gitee.com/timedb/wheatCache/pkg/lru"
"gitee.com/timedb/wheatCache/storage/dao"
"github.com/spf13/viper"
"time"
)
type serverSingle struct {
middleProduce event.ProduceInterface
lruProduce event.ProduceInterface
timeOut time.Duration
lruCache *lru.SingleCache
dao *dao.Dao
}
func NewServer() *serverSingle {
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()),
timeOut: time.Duration(timeOut),
dao: dao.NewDao(lruCache),
}
sysSingleServer = ser
})
return sysSingleServer
}