缓存驱动更换成功,支持3级缓存,memory,以及db
This commit is contained in:
Vendored
+19
-10
@@ -8,13 +8,25 @@ import (
|
||||
)
|
||||
|
||||
type CacheMemory struct {
|
||||
Time int64
|
||||
TimeOut int64
|
||||
DbSet bool
|
||||
SessionSet bool
|
||||
Map
|
||||
Error
|
||||
*Error
|
||||
ContextBase
|
||||
mutex *sync.RWMutex
|
||||
}
|
||||
|
||||
func (this *CacheMemory) GetError() *Error {
|
||||
|
||||
return this.Error
|
||||
|
||||
}
|
||||
|
||||
func (this *CacheMemory) SetError(err *Error) {
|
||||
this.Error = err
|
||||
}
|
||||
|
||||
//获取Cache键只能为string类型
|
||||
func (this *CacheMemory) get(key string) interface{} {
|
||||
this.Error.SetError(nil)
|
||||
@@ -25,8 +37,8 @@ func (this *CacheMemory) get(key string) interface{} {
|
||||
if this.Map[key] == nil {
|
||||
return nil
|
||||
}
|
||||
data := this.Map.Get(key, &this.Error).(cacheData)
|
||||
if this.GetError() != nil {
|
||||
data := this.Map.Get(key, this.Error).(cacheData)
|
||||
if this.Error.GetError() != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -121,21 +133,18 @@ func (this *CacheMemory) Cache(key string, data ...interface{}) *Obj {
|
||||
}
|
||||
|
||||
if len(data) == 1 {
|
||||
if this.Time == 0 {
|
||||
//this.Time = Config.GetInt64("cacheShortTime")
|
||||
}
|
||||
|
||||
tim = tim + this.Time
|
||||
tim = tim + this.TimeOut
|
||||
|
||||
}
|
||||
if len(data) == 2 {
|
||||
this.Error.SetError(nil)
|
||||
tempt := ObjToInt64(data[1], &this.Error)
|
||||
tempt := ObjToInt64(data[1], this.Error)
|
||||
|
||||
if tempt > tim {
|
||||
|
||||
tim = tempt
|
||||
} else if this.GetError() == nil {
|
||||
} else if this.Error.GetError() == nil {
|
||||
|
||||
tim = tim + tempt
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user