You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gocache/ristretto_test.go

41 lines
898 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package gocache
import (
"testing"
)
func TestRistretto(t *testing.T) {
newCache := NewRistretto()
// 字符串
newCache.Set("key1", "测试Ristretto插入数据 1", 1)
key1, _ := newCache.Get("key1")
t.Logf("key1%+v", key1)
newCache.Del("key1")
key1, _ = newCache.Get("key1")
t.Logf("key1%+v", key1)
// 结构体
type name struct {
Test string `json:"test"`
}
newCache.Set("key2", name{"测试Ristretto插入数据 2"}, 1)
key2, _ := newCache.Get("key2")
t.Logf("key2%+v", key2)
t.Logf("key2%+v", key2.(name))
newCache.Del("key2")
key2, _ = newCache.Get("key2")
t.Logf("key2%+v", key2)
// 缓存组件
newCacheCache := newCache.NewCache()
newCacheCache.GetterInterface = func() interface{} {
return name{"测试Ristretto插入数据 3"}
}
key3 := newCacheCache.GetInterface("key3")
t.Logf("key3%+v", key3)
t.Logf("key3%+v", key3.(name))
}