2017-08-04 08:20:59 +00:00
|
|
|
package hotime
|
|
|
|
|
2021-05-23 23:27:41 +00:00
|
|
|
import (
|
|
|
|
. "./cache"
|
|
|
|
. "./common"
|
|
|
|
)
|
|
|
|
|
2017-08-10 10:14:56 +00:00
|
|
|
//session对象
|
2017-08-04 08:20:59 +00:00
|
|
|
type SessionIns struct {
|
2021-05-28 14:52:22 +00:00
|
|
|
*HoTimeCache
|
|
|
|
SessionId string
|
2017-08-04 08:20:59 +00:00
|
|
|
Map
|
2021-05-23 23:27:41 +00:00
|
|
|
ContextBase
|
2017-08-04 08:20:59 +00:00
|
|
|
}
|
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
func (that *SessionIns) set() {
|
2021-05-28 14:52:22 +00:00
|
|
|
that.HoTimeCache.Session(HEAD_SESSION_ADD+that.SessionId, that.Map)
|
2017-08-04 08:20:59 +00:00
|
|
|
}
|
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
func (that *SessionIns) Session(key string, data ...interface{}) *Obj {
|
2017-08-04 08:20:59 +00:00
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
if that.Map == nil {
|
|
|
|
that.get()
|
2017-08-04 08:20:59 +00:00
|
|
|
}
|
|
|
|
|
2017-08-10 10:14:56 +00:00
|
|
|
if len(data) != 0 {
|
|
|
|
if data[0] == nil {
|
2021-05-24 21:08:17 +00:00
|
|
|
delete(that.Map, key)
|
|
|
|
that.set()
|
2017-08-10 10:14:56 +00:00
|
|
|
} else {
|
2021-05-24 21:08:17 +00:00
|
|
|
that.Map[key] = data[0]
|
|
|
|
that.set()
|
2017-08-04 08:20:59 +00:00
|
|
|
}
|
2017-08-10 10:14:56 +00:00
|
|
|
return &Obj{Data: nil}
|
2017-08-04 08:20:59 +00:00
|
|
|
}
|
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
return &Obj{Data: that.Map.Get(key)}
|
2017-08-04 08:20:59 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
func (that *SessionIns) get() {
|
2017-08-04 08:20:59 +00:00
|
|
|
|
2021-05-28 14:52:22 +00:00
|
|
|
that.Map = that.HoTimeCache.Session(HEAD_SESSION_ADD + that.SessionId).ToMap()
|
|
|
|
if that.Map != nil {
|
|
|
|
return
|
2017-08-04 08:20:59 +00:00
|
|
|
}
|
|
|
|
|
2021-05-24 21:08:17 +00:00
|
|
|
that.Map = Map{}
|
2021-05-28 14:52:22 +00:00
|
|
|
that.HoTimeCache.Session(HEAD_SESSION_ADD+that.SessionId, that.Map)
|
2017-08-04 08:20:59 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-05-28 14:52:22 +00:00
|
|
|
func (that *SessionIns) Init(cache *HoTimeCache) {
|
|
|
|
that.HoTimeCache = cache
|
2017-08-10 10:14:56 +00:00
|
|
|
}
|