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