From 257f0a6b6e5fc89b0fc8b6883dad24cc2ff8ef4c Mon Sep 17 00:00:00 2001 From: yanweidong Date: Sat, 20 Sep 2025 11:21:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(with):=20=E4=BC=98=E5=8C=96=20memory=20cach?= =?UTF-8?q?e=20=E9=85=8D=E7=BD=AE=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除未使用的 `encoding/json` 包导入。 调整配置初始化方式,避免不必要的结构体拷贝。 改进日志输出内容,仅显示关键配置项。 --- with/memory.go | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/with/memory.go b/with/memory.go index 89f6a98..85ce176 100644 --- a/with/memory.go +++ b/with/memory.go @@ -2,7 +2,6 @@ package with import ( "context" - "encoding/json" "time" "git.apinb.com/bsm-sdk/core/print" @@ -11,29 +10,26 @@ import ( ) func Memory(cli *bigcache.BigCache, opts *bigcache.Config) { - config := 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, - } - - if opts != nil { - config = *opts + 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(), config) + cli, err = bigcache.New(context.Background(), *opts) if err != nil { print.Error("Memory Cache Fatal Error") panic(err) } - jsonBytes, _ := json.Marshal(config) - print.Success("[BSM - %s] Memory Cache: %s", vars.ServiceKey, jsonBytes) + print.Success("[BSM - %s] Memory Cache: Shards=%d, MaxEntrySize=%d", vars.ServiceKey, opts.Shards, opts.MaxEntrySize) }