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

cache

上级 c7775260
......@@ -26,20 +26,9 @@ type memoryCache struct {
}
// NewMemoryCache create a memory cache
func NewMemoryCache(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())
}
func NewMemoryCache(cache *ristretto.Cache, keyPrefix string, encode encoding.Encoding, newObject func() interface{}) Cache {
return &memoryCache{
client: store,
client: cache,
KeyPrefix: keyPrefix,
encoding: encode,
newObject: newObject,
......
......@@ -6,7 +6,6 @@ import (
"github.com/stretchr/testify/assert"
"gitlab.wanzhuangkj.com/tush/xpkg/encoding"
"gitlab.wanzhuangkj.com/tush/xpkg/gotest"
"gitlab.wanzhuangkj.com/tush/xpkg/utils"
)
......@@ -32,10 +31,10 @@ func newMemoryCache() *gotest.Cache {
}
c := gotest.NewCache(testData)
cachePrefix := ""
c.ICache = NewMemoryCache(cachePrefix, encoding.JSONEncoding{}, func() interface{} {
return &memoryUser{}
})
//cachePrefix := ""
//c.ICache = NewMemoryCache(cachePrefix, encoding.JSONEncoding{}, func() interface{} {
// return &memoryUser{}
//})
return c
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论