fix(with): 优化 memory cache 配置初始化逻辑
移除未使用的 `encoding/json` 包导入。 调整配置初始化方式,避免不必要的结构体拷贝。 改进日志输出内容,仅显示关键配置项。
This commit is contained in:
parent
5e25e8eccc
commit
257f0a6b6e
|
@ -2,7 +2,6 @@ package with
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.apinb.com/bsm-sdk/core/print"
|
"git.apinb.com/bsm-sdk/core/print"
|
||||||
|
@ -11,29 +10,26 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Memory(cli *bigcache.BigCache, opts *bigcache.Config) {
|
func Memory(cli *bigcache.BigCache, opts *bigcache.Config) {
|
||||||
config := bigcache.Config{
|
if opts == nil {
|
||||||
Shards: 1024,
|
opts = bigcache.Config{
|
||||||
LifeWindow: 10 * time.Minute,
|
Shards: 1024,
|
||||||
CleanWindow: 5 * time.Minute,
|
LifeWindow: 10 * time.Minute,
|
||||||
MaxEntriesInWindow: 1000 * 10 * 60,
|
CleanWindow: 5 * time.Minute,
|
||||||
MaxEntrySize: 500,
|
MaxEntriesInWindow: 1000 * 10 * 60,
|
||||||
Verbose: true,
|
MaxEntrySize: 500,
|
||||||
HardMaxCacheSize: 8192,
|
Verbose: true,
|
||||||
OnRemove: nil,
|
HardMaxCacheSize: 8192,
|
||||||
OnRemoveWithReason: nil,
|
OnRemove: nil,
|
||||||
}
|
OnRemoveWithReason: nil,
|
||||||
|
}
|
||||||
if opts != nil {
|
|
||||||
config = *opts
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
cli, err = bigcache.New(context.Background(), config)
|
cli, err = bigcache.New(context.Background(), *opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
print.Error("Memory Cache Fatal Error")
|
print.Error("Memory Cache Fatal Error")
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonBytes, _ := json.Marshal(config)
|
print.Success("[BSM - %s] Memory Cache: Shards=%d, MaxEntrySize=%d", vars.ServiceKey, opts.Shards, opts.MaxEntrySize)
|
||||||
print.Success("[BSM - %s] Memory Cache: %s", vars.ServiceKey, jsonBytes)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue