func MSessionFilter(c *revel.Controller, fc []revel.Filter) { sessionId := c.Session.Id() // 从memcache中得到cache, 赋给session cache := revel.Session(memcache.GetMap(sessionId)) Log("memcache") LogJ(cache) if cache == nil { cache = revel.Session{} cache.Id() } c.Session = cache // Make session vars available in templates as {{.session.xyz}} c.RenderArgs["session"] = c.Session fc[0](c, fc[1:]) // 再把session保存之 LogJ(c.Session) memcache.SetMap(sessionId, c.Session, -1) // 只留下sessionId c.Session = revel.Session{revel.SESSION_ID_KEY: sessionId} }
// SessionFilter is a Revel Filter that retrieves and sets the session cookie. // Within Revel, it is available as a Session attribute on Controller instances. // The name of the Session cookie is set as CookiePrefix + "_SESSION". func SessionFilter(c *revel.Controller, fc []revel.Filter) { session := restoreSession(c.Request.Request) // c.Session, 重新生成一个revel.Session给controller!!! // Log("sessoin--------") // LogJ(session) revelSession := revel.Session(session) // 强制转换 还是同一个对象, 但有个问题, 这样Session.Id()方法是用revel的了 c.Session = revelSession // 生成sessionId c.Session.Id() sessionWasEmpty := len(c.Session) == 0 // Make session vars available in templates as {{.session.xyz}} c.RenderArgs["session"] = c.Session fc[0](c, fc[1:]) // Store the signed session if it could have changed. if len(c.Session) > 0 || !sessionWasEmpty { // 转换成lea.Session session = Session(c.Session) c.SetCookie(session.cookie()) } }