cache refactoring for save and load

This commit is contained in:
Radu Ioan Fericean
2016-06-07 22:43:02 +03:00
parent 95e8230a5c
commit e84e28faae
35 changed files with 736 additions and 605 deletions

View File

@@ -0,0 +1,25 @@
package engine
import (
"testing"
"time"
)
func TestRCacheSetGet(t *testing.T) {
rc := NewResponseCache(5 * time.Second)
rc.Cache("test", &CacheItem{Value: "best"})
v, err := rc.Get("test")
if err != nil || v.Value.(string) != "best" {
t.Error("Error retriving response cache: ", v, err)
}
}
func TestRCacheExpire(t *testing.T) {
rc := NewResponseCache(1 * time.Microsecond)
rc.Cache("test", &CacheItem{Value: "best"})
time.Sleep(1 * time.Millisecond)
_, err := rc.Get("test")
if err == nil {
t.Error("Error expiring response cache: ", err)
}
}