// Put puts value into cache with key and expire time.
// If expired is 0, it will be deleted by next GC operation.
349227
func (c *FileCacher) Put(key string, val interface{}, expire int64) error {
	filename := c.filepath(key)
	item := &Item{val, time.Now().Unix(), expire}
	data, err := EncodeGob(item)
	if err != nil {
		return err
	}

	os.MkdirAll(filepath.Dir(filename), os.ModePerm)
	return ioutil.WriteFile(filename, data, os.ModePerm)
}
304051
func (cache autocertCache) Put(ctx context.Context, name string, data []byte) error {
	coll, closeColl := cache.coll()
	defer closeColl()
	_, err := coll.UpsertId(name, autocertCacheDoc{
		Name: name,
		Data: data,
	})
	if err != nil {
		return errors.Annotatef(err, "cannot store autocert key %q", name)
	}
	return nil
}
594136
func (c *ObjectLRU) Put(obj plumbing.EncodedObject) {
	c.mut.Lock()
	defer c.mut.Unlock()

	if c.cache == nil {
		c.actualSize = 0
		c.cache = make(map[interface{}]*list.Element, 1000)
		c.ll = list.New()
	}

	objSize := FileSize(obj.Size())
	key := obj.Hash()
	if ee, ok := c.cache[key]; ok {
		oldObj := ee.Value.(plumbing.EncodedObject)
		// in this case objSize is a delta: new size - old size
		objSize -= FileSize(oldObj.Size())
		c.ll.MoveToFront(ee)
		ee.Value = obj
	} else {
		if objSize > c.MaxSize {
			return
		}
		ee := c.ll.PushFront(obj)
		c.cache[key] = ee
	}

	c.actualSize += objSize
	for c.actualSize > c.MaxSize {
		last := c.ll.Back()
		if last == nil {
			c.actualSize = 0
			break
		}

		lastObj := last.Value.(plumbing.EncodedObject)
		lastSize := FileSize(lastObj.Size())

		c.ll.Remove(last)
		delete(c.cache, lastObj.Hash())
		c.actualSize -= lastSize
	}
}
1348698
func (c *Context) Put(key string, value interface{}) {
	c.lock.Lock()
	c.contextMap[key] = value
	c.lock.Unlock()
}
84149
func (c *MemoryCacher) Put(key, val string, expire int64) error {
	c.lock.Lock()
	defer c.lock.Unlock()

	c.items[key] = &MemoryItem{
		val:     val,
		created: time.Now().Unix(),
		expire:  expire,
	}
	return nil
}
365766
func (s *redisStorage) Set(key string, val interface{}, expires time.Duration) error {
	item := &cachedItem{Val: val}
	value, err := encodeGob(item)
	if err != nil {
		return err
	}

	status := s.c.SetEx(key, expires, string(value))
	return status.Err()
}
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)
}
170019
func (sc *StorageCache) Put(c context.Context, key storage.CacheKey, data []byte, exp time.Duration) {
	ct := sc.compressionThreshold
	if ct <= 0 {
		ct = defaultCompressionThreshold
	}

	var buf bytes.Buffer
	buf.Grow(len(data) + 1)

	if len(data) < ct {
		// Do not compress the item. Write a "0x00" to indicate that it is
		// not compressed.
		if err := buf.WriteByte(0x00); err != nil {
			log.WithError(err).Warningf(c, "Failed to write compression byte.")
			return
		}
		if _, err := buf.Write(data); err != nil {
			log.WithError(err).Warningf(c, "Failed to write storage cache data.")
			return
		}
	} else {
		// Compress the item. Write a "0x01" to indicate that it is compressed.
		if err := buf.WriteByte(0x01); err != nil {
			log.WithError(err).Warningf(c, "Failed to write compression byte.")
			return
		}

		zw := zlib.NewWriter(&buf)
		if _, err := zw.Write(data); err != nil {
			log.WithError(err).Warningf(c, "Failed to compress storage cache data.")
			zw.Close()
			return
		}
		if err := zw.Close(); err != nil {
			log.WithError(err).Warningf(c, "Failed to close compressed storage cache data.")
			return
		}
	}

	storageCache.LRU(c).Put(c, key, buf.Bytes(), exp)
}
474568
func (c *Cache) Put(ctx context.Context, key storage.CacheKey, val []byte, exp time.Duration) {
	c.mu.Lock()
	defer c.mu.Unlock()

	if c.cacheMap == nil {
		c.cacheMap = make(map[storage.CacheKey][]byte)
	}

	c.cacheMap[key] = val
}
483476
func (kv *KV) Put(key, value []byte) error {
	return kv.db.Write(gkv.Btos(key), value)
}
1014490
func (cache *DiskBlockCacheLocal) Put(
	ctx context.Context, tlfID tlf.ID, blockID kbfsblock.ID, buf []byte,
	serverHalf kbfscrypto.BlockCryptKeyServerHalf) (err error) {
	cache.lock.Lock()
	defer cache.lock.Unlock()
	err = cache.checkCacheLocked("Block(Put)")
	if err != nil {
		return err
	}

	blockLen := len(buf)
	entry, err := cache.encodeBlockCacheEntry(buf, serverHalf)
	if err != nil {
		return err
	}
	encodedLen := int64(len(entry))
	defer func() {
		cache.log.CDebugf(ctx, "Cache Put id=%s tlf=%s bSize=%d entrySize=%d "+
			"cacheType=%s err=%+v", blockID, tlfID, blockLen, encodedLen,
			cache.cacheType, err)
	}()
	blockKey := blockID.Bytes()
	hasKey, err := cache.blockDb.Has(blockKey, nil)
	if err != nil {
		cache.log.CDebugf(ctx, "Cache Put failed due to error from "+
			"blockDb.Has: %+v", err)
		return err
	}
	if !hasKey {
		if cache.cacheType == syncCacheLimitTrackerType {
			bytesAvailable, err := cache.config.DiskLimiter().reserveBytes(
				ctx, cache.cacheType, encodedLen)
			if err != nil {
				cache.log.CWarningf(ctx, "Error obtaining space for the disk "+
					"block cache: %+v", err)
				return err
			}
			if bytesAvailable < 0 {
				return data.CachePutCacheFullError{BlockID: blockID}
			}
		} else {
			hasEnoughSpace, err := cache.evictUntilBytesAvailable(ctx, encodedLen)
			if err != nil {
				return err
			}
			if !hasEnoughSpace {
				return data.CachePutCacheFullError{BlockID: blockID}
			}
		}
		err = cache.blockDb.PutWithMeter(blockKey, entry, cache.putMeter)
		if err != nil {
			if cache.useLimiter() {
				cache.config.DiskLimiter().commitOrRollback(ctx,
					cache.cacheType, encodedLen, 0, false, "")
			}
			return err
		}
		if cache.useLimiter() {
			cache.config.DiskLimiter().commitOrRollback(ctx, cache.cacheType,
				encodedLen, 0, true, "")
		}
		cache.tlfCounts[tlfID]++
		cache.priorityBlockCounts[cache.homeDirs[tlfID]]++
		cache.priorityTlfMap[cache.homeDirs[tlfID]][tlfID]++
		cache.numBlocks++
		encodedLenUint := uint64(encodedLen)
		cache.tlfSizes[tlfID] += encodedLenUint
		cache.addCurrBytes(encodedLenUint)
	}
	tlfKey := cache.tlfKey(tlfID, blockKey)
	hasKey, err = cache.tlfDb.Has(tlfKey, nil)
	if err != nil {
		cache.log.CWarningf(ctx, "Error reading from TLF cache database: %+v",
			err)
	}
	if !hasKey {
		err = cache.tlfDb.Put(tlfKey, []byte{}, nil)
		if err != nil {
			cache.log.CWarningf(ctx,
				"Error writing to TLF cache database: %+v", err)
		}
	}
	md, err := cache.getMetadataLocked(blockID, false)
	if err != nil {
		// Only set the relevant fields if we had trouble getting the metadata.
		// Initially leave TriggeredPrefetch and FinishedPrefetch as false;
		// rely on the later-called UpdateMetadata to fix it.
		md.TlfID = tlfID
		md.BlockSize = uint32(encodedLen)
		err = nil
	}
	return cache.updateMetadataLocked(ctx, blockKey, md, unmetered)
}
1212131
func (kv *KV) Put(key, value []byte) error {
	return kv.db.Update(func(txn *badger.Txn) error {
		return txn.Set(key, value)
	})
}
624242
func (cfs *cacheFSObjects) Put(ctx context.Context, bucket, object string, data *PutObjReader, opts ObjectOptions) error {
	if cfs.diskUsageHigh() {
		select {
		case cfs.purgeChan <- struct{}{}:
		default:
		}
		return errDiskFull
	}
	if !cfs.diskAvailable(data.Size()) {
		return errDiskFull
	}
	if _, err := cfs.GetBucketInfo(ctx, bucket); err != nil {
		pErr := cfs.MakeBucketWithLocation(ctx, bucket, "")
		if pErr != nil {
			return pErr
		}
	}
	_, err := cfs.PutObject(ctx, bucket, object, data, opts)
	// if err is due to disk being offline , mark cache drive as offline
	if IsErr(err, baseErrs...) {
		cfs.setOnline(false)
	}
	return err
}
847825
func (tx *Tx) Put(key []byte, value []byte) error {
	if tx.cellar == nil {
		return ErrTxClosed
	} else if !tx.writable {
		return ErrTxNotWritable
	}
	return tx.segmentBuilder.Put(key, value)
}
1261000
func (batch *UpdateBatch) Put(key []byte, value []byte) {
	if value == nil {
		panic("Nil value not allowed")
	}
	batch.KVs[string(key)] = value
}
128499
func (d *Datastore) Put(k ds.Key, val []byte) error {
	d.buffer[k] = op{value: val}
	if len(d.buffer) > d.maxBufferEntries {
		return d.Flush()
	}
	return nil
}
1004094
func (dds *Delayed) Put(key ds.Key, value []byte) (err error) {
	dds.delay.Wait()
	return dds.ds.Put(key, value)
}