// load gets a value from memcache and decodes its content into session.Values. func (s *MemcacheStore) load(r *http.Request, session *sessions.Session) error { item, err := memcache.Get(context.New(r), session.ID) if err != nil { return err } if err := deserialize(item.Value, &session.Values); err != nil { return err } return nil }
// load gets a value from datastore and decodes its content into // session.Values. func (s *DatastoreStore) load(r *http.Request, session *sessions.Session) error { c := context.New(r) k := datastore.NewKey(c, s.kind, session.ID, 0, nil) entity := Session{} if err := datastore.Get(c, k, &entity); err != nil { return err } if err := deserialize(entity.Value, &session.Values); err != nil { return err } return nil }
// save writes encoded session.Values to memcache. func (s *MemcacheStore) save(r *http.Request, session *sessions.Session) error { if len(session.Values) == 0 { // Don't need to write anything. return nil } serialized, err := serialize(session.Values) if err != nil { return err } err = memcache.Set(context.New(r), &memcache.Item{ Key: session.ID, Value: serialized, }) if err != nil { return err } return nil }
// save writes encoded session.Values to datastore. func (s *DatastoreStore) save(r *http.Request, session *sessions.Session) error { if len(session.Values) == 0 { // Don't need to write anything. return nil } serialized, err := serialize(session.Values) if err != nil { return err } c := context.New(r) k := datastore.NewKey(c, s.kind, session.ID, 0, nil) k, err = datastore.Put(c, k, &Session{ Date: time.Now(), Value: serialized, }) if err != nil { return err } return nil }