提交 b8fbb524 authored 作者: mooncake9527's avatar mooncake9527

cache

上级 c7775260
...@@ -26,20 +26,9 @@ type memoryCache struct { ...@@ -26,20 +26,9 @@ type memoryCache struct {
} }
// NewMemoryCache create a memory cache // NewMemoryCache create a memory cache
func NewMemoryCache(keyPrefix string, encode encoding.Encoding, newObject func() interface{}) Cache { func NewMemoryCache(cache *ristretto.Cache, keyPrefix string, encode encoding.Encoding, newObject func() interface{}) Cache {
// see: https://dgraph.io/blog/post/introducing-ristretto-high-perf-go-cache/
// https://www.start.io/blog/we-chose-ristretto-cache-for-go-heres-why/
config := &ristretto.Config{
NumCounters: 1e7, // number of keys to track frequency of (10M).
MaxCost: 1 << 30, // maximum cost of cache (1GB).
BufferItems: 64, // number of keys per Get buffer.
}
store, err := ristretto.NewCache(config)
if err != nil {
panic("new ristretto cache err:" + err.Error())
}
return &memoryCache{ return &memoryCache{
client: store, client: cache,
KeyPrefix: keyPrefix, KeyPrefix: keyPrefix,
encoding: encode, encoding: encode,
newObject: newObject, newObject: newObject,
......
...@@ -6,7 +6,6 @@ import ( ...@@ -6,7 +6,6 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gitlab.wanzhuangkj.com/tush/xpkg/encoding"
"gitlab.wanzhuangkj.com/tush/xpkg/gotest" "gitlab.wanzhuangkj.com/tush/xpkg/gotest"
"gitlab.wanzhuangkj.com/tush/xpkg/utils" "gitlab.wanzhuangkj.com/tush/xpkg/utils"
) )
...@@ -32,10 +31,10 @@ func newMemoryCache() *gotest.Cache { ...@@ -32,10 +31,10 @@ func newMemoryCache() *gotest.Cache {
} }
c := gotest.NewCache(testData) c := gotest.NewCache(testData)
cachePrefix := "" //cachePrefix := ""
c.ICache = NewMemoryCache(cachePrefix, encoding.JSONEncoding{}, func() interface{} { //c.ICache = NewMemoryCache(cachePrefix, encoding.JSONEncoding{}, func() interface{} {
return &memoryUser{} // return &memoryUser{}
}) //})
return c return c
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论