Compare commits

...

5 Commits

Author SHA1 Message Date
f70f8d94db fix(with): 修复 memory.go 中的配置初始化错误
将 bigcache.Config 结构体实例改为指针传递,确保配置能够正确初始化和传递。
2025-09-20 11:32:24 +08:00
257f0a6b6e fix(with): 优化 memory cache 配置初始化逻辑
移除未使用的 `encoding/json` 包导入。
调整配置初始化方式,避免不必要的结构体拷贝。
改进日志输出内容,仅显示关键配置项。
2025-09-20 11:21:02 +08:00
5e25e8eccc fix(with/etcd): 修改Etcd配置为空时的处理逻辑
当Etcd配置或端点为空时,将panic改为直接返回,避免程序崩溃
2025-09-20 11:08:47 +08:00
4f584726d6 ```
refactor(with): 调整Memory函数参数顺序

将Memory函数的参数顺序从(opts, cli)调整为(cli, opts),
使函数签名更加符合常规的客户端优先参数排列习惯,
提升代码可读性和一致性。
```
2025-09-20 10:59:45 +08:00
b9d144353e ```
refactor(cache): 移除内存缓存和Redis缓存的初始化逻辑

移除了mem包中内存缓存的初始化函数,以及with包中Redis缓存的初始化函数。
这些缓存初始化逻辑将被重构到其他位置或采用新的实现方式。
```
2025-09-20 10:55:06 +08:00
4 changed files with 36 additions and 15 deletions

14
cache/mem/mem.go vendored
View File

@@ -1,14 +0,0 @@
package mem
import (
"git.apinb.com/bsm-sdk/core/vars"
"github.com/FishGoddess/cachego"
)
func New() cachego.Cache {
return cachego.NewCache(
cachego.WithGC(vars.MemGcDuration),
cachego.WithShardings(vars.MemShardings),
cachego.WithLFU(vars.MemLRUMaxNumber),
)
}

View File

@@ -13,7 +13,7 @@ import (
func Etcd(cfg *conf.EtcdConf, cli *clientv3.Client) {
if cfg == nil || len(cfg.Endpoints) == 0 {
panic("Etcd endpoints is Empty!")
return
}
etcdCfg := clientv3.Config{

35
with/memory.go Normal file
View File

@@ -0,0 +1,35 @@
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(cli *bigcache.BigCache, opts *bigcache.Config) {
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)
}