This commit is contained in:
hoteas 2018-06-13 11:10:13 +00:00
parent 9ff8f50fb9
commit 3f0780e6ea
3 changed files with 62 additions and 60 deletions

View File

@ -138,10 +138,12 @@ func (this *CacheRedis) Cache(key string, data ...interface{}) *Obj {
if len(data) == 2 {
this.Error.SetError(nil)
tempt := ObjToInt64(data[1], &this.Error)
if this.GetError() == nil {
if tempt > tim {
tim = tempt
} else if this.GetError() == nil {
tim = tim + tempt
}
}

View File

@ -106,10 +106,11 @@ func (this *CacheDb) Cache(key string, data ...interface{}) *Obj {
this.SetError(nil)
tempt := ObjToInt64(data[1], &this.Error)
if this.GetError() == nil {
if tempt > tim {
tim = tempt
} else if this.GetError() == nil {
tim = tim + tempt
}
}
this.set(key, data[0], tim)

View File

@ -1,9 +1,9 @@
package hotime
import (
"time"
"sync"
"strings"
"sync"
"time"
)
type CacheMemory struct {
@ -24,7 +24,7 @@ func (this *CacheMemory) get(key string) interface{} {
return nil
}
//data:=cacheMap[key];
if data.time <= time.Now().Unix() {
if data.time < time.Now().Unix() {
delete(this.Map, key)
return nil
}
@ -45,8 +45,6 @@ func (this *CacheMemory)refreshMap(){
}()
}
//key value ,时间为时间戳
@ -89,7 +87,6 @@ func (this *CacheMemory) delete(key string) {
func (this *CacheMemory) Cache(key string, data ...interface{}) *Obj {
x := RandX(1, 100000)
if x > 99950 {
this.refreshMap()
@ -98,8 +95,7 @@ func (this *CacheMemory) Cache(key string, data ...interface{}) *Obj {
this.mutex = &sync.RWMutex{}
}
reData:= &Obj{}
reData := &Obj{Data: nil}
if len(data) == 0 {
this.mutex.RLock()
@ -122,15 +118,18 @@ func (this *CacheMemory) Cache(key string, data ...interface{}) *Obj {
this.Time = Config.GetInt64("cacheShortTime")
}
tim += this.Time
tim = tim + this.Time
}
if len(data) == 2 {
this.Error.SetError(nil)
tempt := ObjToInt64(data[1], &this.Error)
if this.GetError() == nil {
if tempt > tim {
tim = tempt
} else if this.GetError() == nil {
tim = tim + tempt
}
}
this.mutex.Lock()