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

43 lines
886 B

2 years ago
package gocache
import (
"testing"
"time"
)
2 years ago
func logGo() *Go {
return NewGo(&GoConfig{
DefaultExpiration: time.Minute * 5,
DefaultClear: time.Minute * 10,
})
}
2 years ago
func TestGo(t *testing.T) {
2 years ago
newCache := logGo()
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(&GoCacheConfig{expiration: 5 * time.Minute})
2 years ago
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
}