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/go_test.go

36 lines
759 B

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