40 lines
1.4 KiB

package memory
import (
"github.com/allegro/bigcache"
"time"
)
// NewBigCache
//
// @Description: 初始化交易-实时数据缓存
// @return *bigcache.BigCache
func NewBigCache() *bigcache.BigCache {
config := bigcache.Config{
// Set the number of partitions, which must be an integer multiple of 2
Shards: 1024,
// After LifeWindow, cached objects are considered inactive, but they are not deleted
LifeWindow: 480 * time.Second,
// After CleanWindow, objects that are considered inactive will be deleted, with 0 representing no operation
CleanWindow: 450 * time.Second,
// Set the maximum number of storage objects, which can only be set during initialization
//MaxEntriesInWindow: 1000 * 10 * 60,
MaxEntriesInWindow: 1,
// The maximum number of bytes for cache objects, which can only be set during initialization
MaxEntrySize: 500,
// Print memory allocation information
Verbose: true,
// Set the maximum cache value (in MB), where 0 represents unlimited
HardMaxCacheSize: 0, //8192
// When the cache expires or is deleted, a callback function can be set with parameters (key, val), and the default is nil
OnRemove: nil,
// When the cache expires or is deleted, a callback function can be set with parameters such as (key, val, reason). The default setting is nil and not set
OnRemoveWithReason: nil,
}
cache, err := bigcache.NewBigCache(config)
if err != nil {
return nil
}
return cache
}