2 Star 5 Fork 0

Minho/cache

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cache_test.go 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
package cache
import (
"testing"
"time"
)
var cacheObject = NewMemoryCache(10000,10000);
type cacheTest struct {
key string;
value interface{};
duration time.Duration;
slidingExpiration int;
regionName string
}
type cacheDataValue struct {
id int;
name string
}
var cacheTestValue = []cacheTest{
cacheTest{ key:"cache1",value: cacheDataValue{ id :1,name:"linux"},duration:time.Minute * 2,slidingExpiration: SlidingExpiration,regionName:"default1"},
cacheTest{ key:"cache2",value:cacheDataValue{id:2,name:"毛晓武"},duration:time.Minute * 2,slidingExpiration: SlidingExpiration,regionName:"default2"},
cacheTest{ key:"cache2",value:cacheDataValue{id:3,name:"江小流"},duration:time.Minute * 2,slidingExpiration: SlidingExpiration,regionName:"default3"},
}
func TestSet(t *testing.T){
for _,v := range cacheTestValue{
err := cacheObject.Add(v.key,v.value,v.duration);
if(err == false){
t.Errorf("key:%s value:%v duration:%v",v.key,v.value,v.duration)
}
}
}
func TestGet(t *testing.T){
for _, v := range cacheTestValue{
value,ok := cacheObject.Get(v.key);
if(!ok){
t.Errorf("key:%s value:%v duration:%v",v.key,v.value,v.duration)
}else{
value := value.(cacheDataValue);
t.Logf("id=%v name=%s",value.id,value.name)
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/longfei6671/cache.git
git@gitee.com:longfei6671/cache.git
longfei6671
cache
cache
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385