```
refactor(cache): 移除内存缓存和Redis缓存的初始化逻辑 移除了mem包中内存缓存的初始化函数,以及with包中Redis缓存的初始化函数。 这些缓存初始化逻辑将被重构到其他位置或采用新的实现方式。 ```
This commit is contained in:
parent
7e7fa16441
commit
b9d144353e
|
@ -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),
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package with
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"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) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
cli, err = bigcache.New(context.Background(), config)
|
||||||
|
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)
|
||||||
|
}
|
Loading…
Reference in New Issue