hotime/session.go
2017-08-10 10:14:56 +00:00

72 lines
1.3 KiB
Go

package hotime
//session对象
type SessionIns struct {
ShortCache CacheIns
LongCache CacheIns
SessionId string
Map
Error
}
func (this *SessionIns) set() {
if this.ShortCache != nil {
this.ShortCache.Cache(SESSION_TYPE+this.SessionId, this.Map)
}
if this.LongCache != nil {
this.LongCache.Cache(SESSION_TYPE+this.SessionId, this.Map)
}
}
func (this *SessionIns) Session(key string, data ...interface{}) *Obj {
if this.Map == nil {
this.get()
}
if len(data) != 0 {
if data[0] == nil {
delete(this.Map, key)
this.set()
} else {
this.Map[key] = data[0]
this.set()
}
return &Obj{Data: nil}
}
return &Obj{Data: this.Map.Get(key)}
}
func (this *SessionIns) get() {
if this.ShortCache != nil {
this.Map = this.ShortCache.Cache(SESSION_TYPE + this.SessionId).ToMap()
if this.Map != nil {
return
}
}
if this.LongCache != nil {
this.Map = this.LongCache.Cache(SESSION_TYPE + this.SessionId).ToMap()
if this.Map != nil {
if this.ShortCache != nil {
this.ShortCache.Cache(SESSION_TYPE+this.SessionId, this.Map)
}
return
}
}
this.Map = Map{}
this.ShortCache.Cache(SESSION_TYPE+this.SessionId, this.Map)
return
}
func (this *SessionIns) Init(short CacheIns, long CacheIns) {
this.ShortCache = short
this.LongCache = long
}