1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-26 03:11:30 +00:00

for issue #1530, accept @JessonChan's suggestion

This commit is contained in:
youngsterxyf 2016-01-08 20:16:58 +08:00
parent bb43d3a78c
commit 0b0904db13
9 changed files with 11 additions and 11 deletions

2
cache/README.md vendored
View File

@ -26,7 +26,7 @@ Then init a Cache (example with memory adapter)
Use it like this: Use it like this:
bm.Put("astaxie", 1, time.Second * 10) bm.Put("astaxie", 1, 10 * time.Second)
bm.Get("astaxie") bm.Get("astaxie")
bm.IsExist("astaxie") bm.IsExist("astaxie")
bm.Delete("astaxie") bm.Delete("astaxie")

4
cache/cache.go vendored
View File

@ -23,7 +23,7 @@
// //
// Use it like this: // Use it like this:
// //
// bm.Put("astaxie", 1, time.Second * 10) // bm.Put("astaxie", 1, 10 * time.Second)
// bm.Get("astaxie") // bm.Get("astaxie")
// bm.IsExist("astaxie") // bm.IsExist("astaxie")
// bm.Delete("astaxie") // bm.Delete("astaxie")
@ -40,7 +40,7 @@ import (
// usage: // usage:
// cache.Register("file",cache.NewFileCache) // this operation is run in init method of file.go. // cache.Register("file",cache.NewFileCache) // this operation is run in init method of file.go.
// c,err := cache.NewCache("file","{....}") // c,err := cache.NewCache("file","{....}")
// c.Put("key",value, time.Second * 3600) // c.Put("key",value, 3600 * time.Second)
// v := c.Get("key") // v := c.Get("key")
// //
// c.Incr("counter") // now is 1 // c.Incr("counter") // now is 1

4
cache/cache_test.go vendored
View File

@ -25,7 +25,7 @@ func TestCache(t *testing.T) {
if err != nil { if err != nil {
t.Error("init err") t.Error("init err")
} }
timeoutDuration := time.Second * 10 timeoutDuration := 10 * time.Second
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil { if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
t.Error("set Error", err) t.Error("set Error", err)
} }
@ -102,7 +102,7 @@ func TestFileCache(t *testing.T) {
if err != nil { if err != nil {
t.Error("init err") t.Error("init err")
} }
timeoutDuration := time.Second * 10 timeoutDuration := 10 * time.Second
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil { if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
t.Error("set Error", err) t.Error("set Error", err)
} }

2
cache/file.go vendored
View File

@ -147,7 +147,7 @@ func (fc *FileCache) Put(key string, val interface{}, timeout time.Duration) err
item := FileCacheItem{Data: val} item := FileCacheItem{Data: val}
if timeout == FileCacheEmbedExpiry { 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 { } else {
item.Expired = time.Now().Add(timeout) item.Expired = time.Now().Add(timeout)
} }

View File

@ -100,7 +100,7 @@ func (rc *Cache) Put(key string, val interface{}, timeout time.Duration) error {
if !ok { if !ok {
return errors.New("val must string") 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) return rc.conn.Set(&item)
} }

View File

@ -28,7 +28,7 @@ func TestMemcacheCache(t *testing.T) {
if err != nil { if err != nil {
t.Error("init err") t.Error("init err")
} }
timeoutDuration := time.Second * 10 timeoutDuration := 10 * time.Second
if err = bm.Put("astaxie", "1", timeoutDuration); err != nil { if err = bm.Put("astaxie", "1", timeoutDuration); err != nil {
t.Error("set Error", err) t.Error("set Error", err)
} }

2
cache/memory.go vendored
View File

@ -200,7 +200,7 @@ func (bc *MemoryCache) StartAndGC(config string) error {
cf = make(map[string]int) cf = make(map[string]int)
cf["interval"] = DefaultEvery cf["interval"] = DefaultEvery
} }
dur := time.Second * time.Duration(cf["interval"]) dur := time.Duration(cf["interval"]) * time.Second
bc.Every = cf["interval"] bc.Every = cf["interval"]
bc.dur = dur bc.dur = dur
go bc.vaccuum() go bc.vaccuum()

View File

@ -111,7 +111,7 @@ ERROR:
// Put put cache to redis. // Put put cache to redis.
func (rc *Cache) Put(key string, val interface{}, timeout time.Duration) error { func (rc *Cache) Put(key string, val interface{}, timeout time.Duration) error {
var err 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 return err
} }

View File

@ -28,7 +28,7 @@ func TestRedisCache(t *testing.T) {
if err != nil { if err != nil {
t.Error("init err") t.Error("init err")
} }
timeoutDuration := time.Second * 10 timeoutDuration := 10 * time.Second
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil { if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
t.Error("set Error", err) t.Error("set Error", err)
} }