37 lines
831 B
Go
37 lines
831 B
Go
package with
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"git.apinb.com/bsm-sdk/core/print"
|
|
"git.apinb.com/bsm-sdk/core/vars"
|
|
"github.com/allegro/bigcache/v3"
|
|
)
|
|
|
|
func Memory(opts *bigcache.Config) (cli *bigcache.BigCache) {
|
|
if opts == nil {
|
|
opts = &bigcache.Config{
|
|
Shards: 1024,
|
|
LifeWindow: 10 * time.Minute,
|
|
CleanWindow: 5 * time.Minute,
|
|
MaxEntriesInWindow: 1000 * 10 * 60,
|
|
MaxEntrySize: 500,
|
|
Verbose: true,
|
|
HardMaxCacheSize: 8192,
|
|
OnRemove: nil,
|
|
OnRemoveWithReason: nil,
|
|
}
|
|
}
|
|
|
|
var err error
|
|
cli, err = bigcache.New(context.Background(), *opts)
|
|
if err != nil {
|
|
print.Error("Memory Cache Fatal Error")
|
|
panic(err)
|
|
}
|
|
|
|
print.Success("[BSM - %s] Memory Cache: Shards=%d, MaxEntrySize=%d", vars.ServiceKey, opts.Shards, opts.MaxEntrySize)
|
|
return
|
|
}
|