mirror of
https://github.com/astaxie/beego.git
synced 2024-11-14 06:30:55 +00:00
39 lines
620 B
Go
39 lines
620 B
Go
|
package cache
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func Test_cache(t *testing.T) {
|
||
|
bm, err := NewCache("memory", `{"interval":60}`)
|
||
|
if err != nil {
|
||
|
t.Error("init err")
|
||
|
}
|
||
|
if err = bm.Put("astaxie", 1, 10); err != nil {
|
||
|
t.Error("set Error", err)
|
||
|
}
|
||
|
if !bm.IsExist("astaxie") {
|
||
|
t.Error("check err")
|
||
|
}
|
||
|
|
||
|
if v := bm.Get("astaxie"); v.(int) != 1 {
|
||
|
t.Error("get err")
|
||
|
}
|
||
|
|
||
|
time.Sleep(70 * time.Second)
|
||
|
|
||
|
if bm.IsExist("astaxie") {
|
||
|
t.Error("check err")
|
||
|
}
|
||
|
|
||
|
if err = bm.Put("astaxie", 1, 10); err != nil {
|
||
|
t.Error("set Error", err)
|
||
|
}
|
||
|
|
||
|
bm.Delete("astaxie")
|
||
|
if bm.IsExist("astaxie") {
|
||
|
t.Error("delete err")
|
||
|
}
|
||
|
}
|