// Save the session into the store.
343136
func (this *RedisStore) Set(sess *Session) error {
	b, err := json.Marshal(sess)
	if err != nil {
		return err
	}
	key := sess.ID()
	if this.opts.KeyPrefix != "" {
		key = this.opts.KeyPrefix + ":" + sess.ID()
	}
	ttl := sess.MaxAge()
	if ttl == 0 {
		// Browser session, set to specified TTL
		ttl = this.opts.BrowserSessServerTTL
		if ttl == 0 {
			ttl = 2 * 24 * time.Hour // Default to 2 days
		}
	}
	_, err = this.conn.Do("SETEX", key, int(ttl.Seconds()), b)
	if err != nil {
		return err
	}
	return nil
}
634821
func (s *Store) Save(i interface{}) error {
	location := s.Path(i)

	b, err := yaml.Marshal(i)
	if err != nil {
		return err
	}

	return ioutil.WriteFile(location, b, 0644)
}
229247
func (ag *AuthGroup) Save(db XODB) error {
	if ag.Exists() {
		return ag.Update(db)
	}

	return ag.Insert(db)
}
42676
func Save(db DB, table string, src interface{}) error {
	return Default.Save(db, table, src)
}
90258
func (s *SortCommand) Store(destination string) *SortCommand {
	s.store = destination
	return s
}
187025
func (s *PacketStore) Save(pkt packet.Generic) {
	s.mutex.Lock()
	defer s.mutex.Unlock()

	id, ok := packet.GetID(pkt)
	if ok {
		s.packets[id] = pkt
	}
}
1192950
func (fs *FileSessionStore) SessionRelease(w http.ResponseWriter) {
	b, err := EncodeGob(fs.values)
	if err != nil {
		SLogger.Println(err)
		return
	}
	_, err = os.Stat(path.Join(filepder.savePath, string(fs.sid[0]), string(fs.sid[1]), fs.sid))
	var f *os.File
	if err == nil {
		f, err = os.OpenFile(path.Join(filepder.savePath, string(fs.sid[0]), string(fs.sid[1]), fs.sid), os.O_RDWR, 0777)
		SLogger.Println(err)
	} else if os.IsNotExist(err) {
		f, err = os.Create(path.Join(filepder.savePath, string(fs.sid[0]), string(fs.sid[1]), fs.sid))
		SLogger.Println(err)
	} else {
		return
	}
	f.Truncate(0)
	f.Seek(0, 0)
	f.Write(b)
	f.Close()
}
1193103
func (s *sessionV8) Save() *probe.Error {
	s.mutex.Lock()
	defer s.mutex.Unlock()

	if s.DataFP.dirty {
		if err := s.DataFP.Sync(); err != nil {
			return probe.NewError(err)
		}
		s.DataFP.dirty = false
	}

	qs, e := quick.NewConfig(s.Header, nil)
	if e != nil {
		return probe.NewError(e).Trace(s.SessionID)
	}

	sessionFile, err := getSessionFile(s.SessionID)
	if err != nil {
		return err.Trace(s.SessionID)
	}
	e = qs.Save(sessionFile)
	if e != nil {
		return probe.NewError(e).Trace(sessionFile)
	}
	return nil
}
302632
func (api UsersAPI) SaveKeyStoreKey(w http.ResponseWriter, r *http.Request) {
	username := mux.Vars(r)["username"]
	globalid := context.Get(r, "client_id").(string)

	body := keystore.KeyStoreKey{}

	if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
		log.Debug("Keystore key decoding failed: ", err)
		http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
		return
	}

	// set/update the username and globalid values to those from the authentication
	body.Username = username
	body.Globalid = globalid
	// set the keys timestamp
	body.KeyData.TimeStamp = db.DateTime(time.Now())

	if !body.Validate() {
		http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
		return
	}

	mgr := keystore.NewManager(r)

	// check if this user/organization already has a key under this label
	if _, err := mgr.GetKeyStoreKey(username, globalid, body.Label); err == nil {
		http.Error(w, http.StatusText(http.StatusConflict), http.StatusConflict)
		return
	}

	err := mgr.Create(&body)
	if err != nil {
		log.Error("error while saving keystore key: ", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	key, err := mgr.GetKeyStoreKey(username, globalid, body.Label)
	if err != nil {
		log.Error("error while retrieving keystore key: ", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	w.Header().Set("Content-type", "application/json")
	w.WriteHeader(http.StatusCreated)
	json.NewEncoder(w).Encode(key)
}
936149
func (s *DbSession) Save(document Document) error {
	coll := s.collection(document.CollectionName())
	err := coll.Insert(document)
	if err != nil {
		return err
	}
	return nil
}
777469
func New(config Config) session.Store {
	s := &memoryStore{
		gcInterval: config.GCInterval,
		l:          make(map[interface{}]*item),
	}
	if s.gcInterval > 0 {
		time.AfterFunc(s.gcInterval, s.gcWorker)
	}
	return s
}
729876
func (query Query) Save(record interface{}) error {
	rv := reflect.ValueOf(record)
	rt := rv.Type()
	if rt.Kind() == reflect.Ptr && rt.Elem().Kind() == reflect.Slice {
		// Put multiple records
		rv = rv.Elem()

		// if it's an empty slice, do nothing
		if rv.Len() == 0 {
			return nil
		}

		if query.Condition.None() {
			// InsertAll
			chs := []*changeset.Changeset{}

			for i := 0; i < rv.Len(); i++ {
				ch := changeset.Convert(rv.Index(i).Interface())
				changeset.DeleteChange(ch, "id")
				chs = append(chs, ch)
			}

			return query.Insert(record, chs...)
		}

		// Update only with first record definition.
		ch := changeset.Convert(rv.Index(0).Interface())
		changeset.DeleteChange(ch, "id")
		changeset.DeleteChange(ch, "created_at")
		return query.Update(record, ch)
	}

	// Put single records
	ch := changeset.Convert(record)
	changeset.DeleteChange(ch, "id")

	if query.Condition.None() {
		return query.Insert(record, ch)
	}

	// remove created_at from changeset
	changeset.DeleteChange(ch, "created_at")

	return query.Update(record, ch)
}
87227
func (c *nativeStore) Store(authConfig types.AuthConfig) error {
	if err := c.storeCredentialsInStore(authConfig); err != nil {
		return err
	}
	authConfig.Username = ""
	authConfig.Password = ""
	authConfig.IdentityToken = ""

	// Fallback to old credential in plain text to save only the email
	return c.fileStore.Store(authConfig)
}
1167352
func (s *DumbMemoryStore) save(session *sessions.Session) error {
	encoded, err := securecookie.EncodeMulti(session.Name(), session.Values,
		s.Codecs...)
	if err != nil {
		return err
	}

	s.Data[session.ID] = encoded

	return nil
}
575965
func (s *EventStore) Save(ctx context.Context, events []eh.Event, originalVersion int) error {
	if len(events) == 0 {
		return eh.EventStoreError{
			Err:       eh.ErrNoEventsToAppend,
			Namespace: eh.NamespaceFromContext(ctx),
		}
	}

	sess := s.session.Copy()
	defer sess.Close()

	// Build all event records, with incrementing versions starting from the
	// original aggregate version.
	dbEvents := make([]dbEvent, len(events))
	aggregateID := events[0].AggregateID()
	version := originalVersion
	for i, event := range events {
		// Only accept events belonging to the same aggregate.
		if event.AggregateID() != aggregateID {
			return eh.EventStoreError{
				Err:       eh.ErrInvalidEvent,
				Namespace: eh.NamespaceFromContext(ctx),
			}
		}

		// Only accept events that apply to the correct aggregate version.
		if event.Version() != version+1 {
			return eh.EventStoreError{
				Err:       eh.ErrIncorrectEventVersion,
				Namespace: eh.NamespaceFromContext(ctx),
			}
		}

		// Create the event record for the DB.
		e, err := newDBEvent(ctx, event)
		if err != nil {
			return err
		}
		dbEvents[i] = *e
		version++
	}

	// Either insert a new aggregate or append to an existing.
	if originalVersion == 0 {
		aggregate := aggregateRecord{
			AggregateID: aggregateID.String(),
			Version:     len(dbEvents),
			Events:      dbEvents,
		}

		if err := sess.DB(s.dbName(ctx)).C("events").Insert(aggregate); err != nil {
			return eh.EventStoreError{
				BaseErr:   err,
				Err:       ErrCouldNotSaveAggregate,
				Namespace: eh.NamespaceFromContext(ctx),
			}
		}
	} else {
		// Increment aggregate version on insert of new event record, and
		// only insert if version of aggregate is matching (ie not changed
		// since loading the aggregate).
		if err := sess.DB(s.dbName(ctx)).C("events").Update(
			bson.M{
				"_id":     aggregateID.String(),
				"version": originalVersion,
			},
			bson.M{
				"$push": bson.M{"events": bson.M{"$each": dbEvents}},
				"$inc":  bson.M{"version": len(dbEvents)},
			},
		); err != nil {
			return eh.EventStoreError{
				BaseErr:   err,
				Err:       ErrCouldNotSaveAggregate,
				Namespace: eh.NamespaceFromContext(ctx),
			}
		}
	}

	return nil
}
1315557
func (client *Client) Save() error {
    _, err := client.sendCommand("SAVE")
    if err != nil {
        return err
    }
    return nil
}
645244
func Sessions(name string, store Store) negroni.HandlerFunc {
	return func(res http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
		// Map to the Session interface
		s := &session{name, r, store, nil, false}

		// Add our session to the context we got from our request
		ctx := context.WithValue(r.Context(), sessionKey, s)

		// Use before hook to save out the session
		rw := res.(negroni.ResponseWriter)
		rw.Before(func(negroni.ResponseWriter) {
			if s.Written() {
				check(s.Session().Save(r, res))
			}
		})

		// Wrap our request with the new context
		r = r.WithContext(ctx)

		next(rw, r)
	}
}