You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.7 KiB

package memory
import (
"github.com/allegro/bigcache"
"github.com/shopspring/decimal"
"matchmaking-system/internal/pkg/utils"
)
var (
// 现货
SpotsCache *bigcache.BigCache // 现货行情缓存
// 合约
ContractCache *bigcache.BigCache // 合约行情缓存
ContractPriceSetUp *bigcache.BigCache // 合约插针价格缓存
ContractFloating *bigcache.BigCache // 合约统计总浮动盈亏
// 秒合约
SecondCache *bigcache.BigCache // 秒合约缓存
SecondPriceSetUp *bigcache.BigCache // 秒合约插针缓存
)
// init
//
// @Description: 初始化虚拟币-内存缓存
func init() {
// 数字币-现货
SpotsCache = NewBigCache()
// 数字币-合约
ContractCache = NewBigCache()
ContractPriceSetUp = NewBigCache()
ContractFloating = NewBigCache()
// 数字币-秒合约
SecondCache = NewBigCache()
SecondPriceSetUp = NewBigCache()
}
// GetContractCache
//
// @Description: 虚拟币-合约插针数据
// @param key
// @return []byte
// @return error
func GetContractCache(key string) ([]byte, error) {
conP, err := ContractPriceSetUp.Get(key)
if err != nil || string(conP) == decimal.Zero.String() || len(utils.StrReplace(string(conP))) == 0 {
conN, errs := ContractCache.Get(key)
if errs != nil {
return []byte{}, errs
}
return conN, nil
}
return conP, err
}
// GetSecondCache
//
// @Description: 虚拟币-秒合约插针数据
// @param key
// @return []byte
// @return error
func GetSecondCache(key string) ([]byte, error) {
conP, err := SecondPriceSetUp.Get(key)
if err != nil || string(conP) == decimal.Zero.String() || len(utils.StrReplace(string(conP))) == 0 {
conN, errs := SecondCache.Get(key)
if errs != nil {
return []byte{}, errs
}
return conN, nil
}
return conP, err
}