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.

62 lines
1.5 KiB

package memory
import (
"github.com/allegro/bigcache"
"github.com/shopspring/decimal"
"matchmaking-system/internal/pkg/utils"
)
var (
ForexCache *bigcache.BigCache // 外汇买一卖一报价缓存
ForexPriceSetUp *bigcache.BigCache // 外汇插针价格缓存
ForexFloating *bigcache.BigCache // 外汇统计总浮动盈亏
ForexImmediateCache *bigcache.BigCache // 外汇即时报价缓存
)
// init
//
// @Description: 初始化内存缓存
func init() {
ForexCache = NewBigCache()
ForexPriceSetUp = NewBigCache()
ForexFloating = NewBigCache()
ForexImmediateCache = NewBigCache()
}
// GetForexCache
//
// @Description: 外汇行情
// @param key
// @return []byte
// @return error
func GetForexCache(key string) ([]byte, error) {
conP, err := ForexPriceSetUp.Get(key)
if err != nil || string(conP) == decimal.Zero.String() || len(utils.StrReplace(string(conP))) == 0 {
conN, errs := ForexCache.Get(key)
if errs != nil {
return []byte{}, errs
}
return conN, nil
}
return conP, err
}
// GetForexImmediateCache
//
// @Description: 外汇即时报价
// @param key
// @return []byte
// @return error
func GetForexImmediateCache(key string) ([]byte, error) {
conP, err := ForexPriceSetUp.Get(key)
if err != nil || string(conP) == decimal.Zero.String() || len(utils.StrReplace(string(conP))) == 0 {
conN, errs := ForexImmediateCache.Get(key)
if errs != nil {
return []byte{}, errs
}
return conN, nil
}
return conP, err
}