// Set/Add/Replace a key/value pair in the cache.
3365
func (c *Client) setGeneric(op opCode, key, val string, ocas uint64, flags, exp uint32) (cas uint64, err error) {
	// Request : MUST key, value, extras ([0..3] flags, [4..7] expiration)
	// Response: MUST NOT key, value, extras
	// CAS: If a CAS is specified (non-zero), all sets only succeed if the key
	//      exists and has the CAS specified. Otherwise, an error is returned.
	m := &msg{
		header: header{
			Op:  op,
			CAS: ocas,
		},
		iextras: []interface{}{flags, exp},
		key:     key,
		val:     val,
	}

	err = c.perform(m)
	return m.CAS, err
}
955426
func (c *PostgresCacher) Put(key string, val interface{}, expire int64) error {
	item := &cache.Item{Val: val}
	data, err := cache.EncodeGob(item)
	if err != nil {
		return err
	}

	now := time.Now().Unix()
	if c.IsExist(key) {
		_, err = c.c.Exec("UPDATE cache SET data=$1, created=$2, expire=$3 WHERE key=$4", data, now, expire, c.md5(key))
	} else {
		_, err = c.c.Exec("INSERT INTO cache(key,data,created,expire) VALUES($1,$2,$3,$4)", c.md5(key), data, now, expire)
	}
	return err
}
1147403
func (c *Cache) Add(key, value interface{}) (evicted bool) {
	c.lock.Lock()
	evicted = c.lru.Add(key, value)
	c.lock.Unlock()
	return evicted
}
598614
func (c *keyValueChanger) SetKey(key string) (string, error) {
	if c.err != nil {
		return "", c.err
	}
	if !c.node.container.duplicates {
		if c.node.hasDuplicateSibling(key) {
			return "", errors.New(ErrDuplicate, errorMessages)
		}
	}
	current := c.node.content.key().(string)
	c.node.content = keyValue{key, c.node.content.value()}
	return current, nil
}
59171
func (f *Values) Set(key, val string) {
	for i, v := range f.values {
		if v.Key == key {
			f.values[i].Value = val
			return
		}
	}

	f.Add(key, val)
}
1236486
func (c *TwoQueueCache) Add(key, value interface{}) {
	c.lock.Lock()
	defer c.lock.Unlock()

	// Check if the value is frequently used already,
	// and just update the value
	if c.frequent.Contains(key) {
		c.frequent.Add(key, value)
		return
	}

	// Check if the value is recently used, and promote
	// the value into the frequent list
	if c.recent.Contains(key) {
		c.recent.Remove(key)
		c.frequent.Add(key, value)
		return
	}

	// If the value was recently evicted, add it to the
	// frequently used list
	if c.recentEvict.Contains(key) {
		c.ensureSpace(true)
		c.recentEvict.Remove(key)
		c.frequent.Add(key, value)
		return
	}

	// Add to the recently seen list
	c.ensureSpace(false)
	c.recent.Add(key, value)
	return
}
1245922
func (c *Cache) Set(key string, resp []byte) {
	key = keyToFilename(key)
	c.d.WriteStream(key, bytes.NewReader(resp), true)
}
687964
func (r *replacer) Set(key, value string) {
	r.customReplacements["{"+key+"}"] = value
}
727889
func (l *LFUNoTS) set(key string, value interface{}) error {
	res, err := l.cache.Get(key)
	if err != nil && err != ErrNotFound {
		return err
	}

	if err == ErrNotFound {
		//create new cache item
		ci := newCacheItem(key, value)

		// if cache size si reached to max size
		// then first remove lfu item from the list
		if l.currentSize >= l.size {
			// then evict some data from head of linked list.
			l.evict(l.frequencyList.Front())
		}

		l.cache.Set(key, ci)
		l.incr(ci)

	} else {
		//update existing one
		val := res.(*cacheItem)
		val.v = value
		l.cache.Set(key, val)
		l.incr(res.(*cacheItem))
	}

	return nil
}
982583
func (c *LedisCacher) Put(key string, val interface{}, expire int64) (err error) {
	if expire == 0 {
		if err = c.c.Set([]byte(key), []byte(com.ToStr(val))); err != nil {
			return err
		}
		_, err = c.c.HSet([]byte(key), defaultHSetName, []byte("0"))
		return err
	}

	if err = c.c.SetEX([]byte(key), expire, []byte(com.ToStr(val))); err != nil {
		return err
	}
	_, err = c.c.HSet([]byte(key), defaultHSetName, []byte(com.ToStr(time.Now().Add(time.Duration(expire)*time.Second).Unix())))
	return err
}
945081
func (c *pubKeyCache) add(candidate cachedPubKey) {
	if len(c.keys) < maxCachedPubKeys {
		c.keys = append(c.keys, candidate)
	}
}
1192756
func (c *Cache) Set(_ context.Context, key dataloader.Key, value dataloader.Thunk) {
	c.ARCCache.Add(key, value)
}
1369810
func (c *Cache) Set(key string, value interface{}, size int64) {
	c.Lock()
	defer c.Unlock()

	var it *Item
	elem, ok := c.m[key]
	if ok {
		// Element exists, push it to front,
		// and then update value etc.
		it = elem.Value.(*Item)
		c.size -= it.Size
		c.l.MoveToFront(elem)
	} else {
		// Insert new element.
		it = &Item{Key: key}
		elem = c.l.PushFront(it)
		c.m[key] = elem
	}
	// Set or update item content.
	it.Value = value
	it.Size = size
	if it.Size < 0 {
		panic("cache: value has negative size")
	}
	it.ModTime = time.Now()
	it.AccessTime = it.ModTime

	// Update cache size.
	if it.Size >= math.MaxInt64-c.size {
		panic("cache: value size is too big")
	}
	c.size += it.Size

	c.enforceCapacity()
}
721977
func (s *memcachedStorage) Set(key string, val interface{}, expires time.Duration) error {
	item := &cachedItem{Val: val}
	bytes, err := encodeGob(item)
	if err != nil {
		return err
	}

	var expiresInSeconds int64
	if expires != 0 {
		expiresInSeconds = int64(expires) / int64(time.Second)
	}

	memcachedItem := newItem(key, bytes, int32(expiresInSeconds))
	return s.c.Set(memcachedItem)
}
151094
func (c *Cache) Set(_ context.Context, key dataloader.Key, value dataloader.Thunk) {
	c.c.Set(key.String(), value, 0)
}
724526
func (ec *Cache) Set(k string, v interface{}, size uint64, expire int32) {
	ec.Lock()
	ec.actualSet(k, v, size, expire)
	ec.Unlock()
}
938617
func (c *SimpleLRUCache) Set(key string, value interface{}) {
	item := cacheItem{
		key:     key,
		value:   value,
		expires: timeFunc().Add(c.expiration),
	}

	c.lruCache.Add(key, item)
}