diff --git a/cache/README.md b/cache/README.md index c8cb7454..957790e7 100644 --- a/cache/README.md +++ b/cache/README.md @@ -26,7 +26,7 @@ Then init a Cache (example with memory adapter) Use it like this: - bm.Put("astaxie", 1, time.Second * 10) + bm.Put("astaxie", 1, 10 * time.Second) bm.Get("astaxie") bm.IsExist("astaxie") bm.Delete("astaxie") diff --git a/cache/cache.go b/cache/cache.go index 78643aea..2008402e 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -23,7 +23,7 @@ // // Use it like this: // -// bm.Put("astaxie", 1, time.Second * 10) +// bm.Put("astaxie", 1, 10 * time.Second) // bm.Get("astaxie") // bm.IsExist("astaxie") // bm.Delete("astaxie") @@ -40,7 +40,7 @@ import ( // usage: // cache.Register("file",cache.NewFileCache) // this operation is run in init method of file.go. // c,err := cache.NewCache("file","{....}") -// c.Put("key",value, time.Second * 3600) +// c.Put("key",value, 3600 * time.Second) // v := c.Get("key") // // c.Incr("counter") // now is 1 diff --git a/cache/cache_test.go b/cache/cache_test.go index 73e593e9..9ceb606a 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -25,7 +25,7 @@ func TestCache(t *testing.T) { if err != nil { t.Error("init err") } - timeoutDuration := time.Second * 10 + timeoutDuration := 10 * time.Second if err = bm.Put("astaxie", 1, timeoutDuration); err != nil { t.Error("set Error", err) } @@ -102,7 +102,7 @@ func TestFileCache(t *testing.T) { if err != nil { t.Error("init err") } - timeoutDuration := time.Second * 10 + timeoutDuration := 10 * time.Second if err = bm.Put("astaxie", 1, timeoutDuration); err != nil { t.Error("set Error", err) } diff --git a/cache/file.go b/cache/file.go index 80f93bce..3a7aa8b0 100644 --- a/cache/file.go +++ b/cache/file.go @@ -147,7 +147,7 @@ func (fc *FileCache) Put(key string, val interface{}, timeout time.Duration) err item := FileCacheItem{Data: val} if timeout == FileCacheEmbedExpiry { - item.Expired = time.Now().Add(time.Second * (86400 * 365 * 10)) // ten years + item.Expired = time.Now().Add((86400 * 365 * 10) * time.Second) // ten years } else { item.Expired = time.Now().Add(timeout) } diff --git a/cache/memcache/memcache.go b/cache/memcache/memcache.go index ea77be38..15ea5d3e 100644 --- a/cache/memcache/memcache.go +++ b/cache/memcache/memcache.go @@ -100,7 +100,7 @@ func (rc *Cache) Put(key string, val interface{}, timeout time.Duration) error { if !ok { return errors.New("val must string") } - item := memcache.Item{Key: key, Value: []byte(v), Expiration: int32(timeout.Seconds())} + item := memcache.Item{Key: key, Value: []byte(v), Expiration: int32(timeout/time.Second)} return rc.conn.Set(&item) } diff --git a/cache/memcache/memcache_test.go b/cache/memcache/memcache_test.go index 93484f6b..19629059 100644 --- a/cache/memcache/memcache_test.go +++ b/cache/memcache/memcache_test.go @@ -28,7 +28,7 @@ func TestMemcacheCache(t *testing.T) { if err != nil { t.Error("init err") } - timeoutDuration := time.Second * 10 + timeoutDuration := 10 * time.Second if err = bm.Put("astaxie", "1", timeoutDuration); err != nil { t.Error("set Error", err) } diff --git a/cache/memory.go b/cache/memory.go index 5ba11b3c..d928afdb 100644 --- a/cache/memory.go +++ b/cache/memory.go @@ -200,7 +200,7 @@ func (bc *MemoryCache) StartAndGC(config string) error { cf = make(map[string]int) cf["interval"] = DefaultEvery } - dur := time.Second * time.Duration(cf["interval"]) + dur := time.Duration(cf["interval"]) * time.Second bc.Every = cf["interval"] bc.dur = dur go bc.vaccuum() diff --git a/cache/redis/redis.go b/cache/redis/redis.go index 316cb423..781e3836 100644 --- a/cache/redis/redis.go +++ b/cache/redis/redis.go @@ -111,7 +111,7 @@ ERROR: // Put put cache to redis. func (rc *Cache) Put(key string, val interface{}, timeout time.Duration) error { var err error - if _, err = rc.do("SETEX", key, int64(timeout.Seconds()), val); err != nil { + if _, err = rc.do("SETEX", key, int64(timeout/time.Second), val); err != nil { return err } diff --git a/cache/redis/redis_test.go b/cache/redis/redis_test.go index 22059508..e51e409b 100644 --- a/cache/redis/redis_test.go +++ b/cache/redis/redis_test.go @@ -28,7 +28,7 @@ func TestRedisCache(t *testing.T) { if err != nil { t.Error("init err") } - timeoutDuration := time.Second * 10 + timeoutDuration := 10 * time.Second if err = bm.Put("astaxie", 1, timeoutDuration); err != nil { t.Error("set Error", err) }