Save an item to cache.

@param (string) $key
@param (mixed)  $value
@param (int)    $ttl

@since 3.0.0

@return object
515579
public function saveItem($key, $value, $ttl = null)
    {
        $_SESSION['__CACHE__'][$key] = json_encode([
            'start' => time(),
            'ttl'   => ($ttl !== null) ? (int) $ttl : $this->ttl,
            'value' => $value,
        ]);

        return $this;
    }
84294
public function set($key, $value, $ttl = null)
    {
        if ($this->enabled()) {
            return $this->cache->save($key, $value, [NetteCache::EXPIRE => $this->makeExpiration($ttl)]);
        }

        return $value;
    }
69626
public function set($key, $value, $ttl = 0)
    {
        $key = (string)$key;
        $ttl = $this->fromDefaultTtl($ttl);

        if ($ttl >= 0) {
            $calculatedTtl = $this->getCalculatedTtl($ttl);

            self::$registry[$key] = [
                'value'   => $this->storageDataStructure($value),
                'expires' => new DateTime(\date('Y-m-d H:i:s', $calculatedTtl))
            ];
        }
        return $this;
    }
1059247
public function set($key, $value, $ttl = null): bool
    {
        if ($this->noCache()) {
            return false;
        }
        $this->checkKey($key);
        $this->filterTtl($ttl);
        $result = $ttl === null ?
            $this->getRedis()->set($this->filterKey($key), $value) : 
            $this->getRedis()->set($this->filterKey($key), $value, (int) $ttl);
        if (!$result) {
            trigger_error('Unable to set in redis cache: ' . $this->getRedis()->getLastError());
            return false;
        }
        return true;
    }
927254
public function set($key, $value, $ttl = null)
	{
		$this->connect();
        
		$oldKey = $key;
		
		$key = $this->formatKey($key);
		$value = $this->encodeValue($value);
		$ttl = $ttl ? $ttl : $this->options['ttl'];

		$this->driver->set($key, $value, $ttl);
        
		return (bool) ($this->driver->getResultCode() == \Memcached::RES_SUCCESS);
	}
677625
public function write($key, $value, $ttl = 0)
    {
        $ttl = ((int) $ttl <= 0) ? 0 : ((int) $ttl + time());

        try {
            $this->delete($key);

            return $this->db
                    ->insert(array(
                        $this->columns['key'] => $this->prefix . $key,
                        $this->columns['data'] => serialize($value),
                        $this->columns['ttl'] => $ttl,
                    ))
                    ->into($this->table);
        } catch (PDOException $e) {
            return false;
        }
    }
906339
public function create($key, $value, $ttl = 0)
    {
        return $request = $this->set($key, $value, $ttl, ['prevExist' => 'false']);
    }
929287
public function set($key, $value, $ttl)
    {
        $curlHandler = $this->curlHandler($key . '?ttl=' . $ttl . 's');

        \curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, true);
        \curl_setopt($curlHandler, CURLOPT_POST, true);
        \curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $value);

        $response = \curl_exec($curlHandler);
        \curl_close($curlHandler);
        return $response;
    }
1268037
public function set($key, $value, $ttl)
    {
        if (!$this->safe) {
            return false;
        }

        return apc_store($key, $value, $ttl);
    }
782251
protected function pack($key, $value, $ttl = 0)
    {
        $content = array(
            'key' => $key,
            'time' => time(),
            'ttl' => $ttl,
            'value' => $value
        );

        return $content;
    }
173202
public function do_set($key, $value, $ttl)
    {
        $redis = is_object($this->_redis) ? $this->_redis : $this->_getRedis();
        $redis->set($this->_prefix . $key, $value, $ttl);
    }
396301
public function insert($key, $value, $ttl, $time)
    {
        if ($this->serializer->isSerializeable($value)) {
            $value = $this->serializer->serialize($value);
        }

        $query = sprintf('INSERT INTO `%s` (`key`, `value`, `ttl`, `created_on`) VALUES (:key, :value, :ttl, :created_on)', $this->table);
        $stmt = $this->pdo->prepare($query);

        return $stmt->execute(array(
            ':'.ConstProviderInterface::CACHE_PARAM_KEY =>  $key,
            ':'.ConstProviderInterface::CACHE_PARAM_VALUE => $value,
            ':'.ConstProviderInterface::CACHE_PARAM_TTL =>  $ttl,
            ':'.ConstProviderInterface::CACHE_PARAM_CREATED_ON => time(),
        ));
    }
1210885
public function set($key, $value, $ttl = null)
    {
        $this->adapter->saveItem($key, $value, $ttl);

        return $this;
    }
910253
public function save($key, $content, $ttl)
    {
        $cacheFile = $this->getCachePath($key);
        $cache = json_encode(['ttl' => (time() + $ttl), 'content' => $content]);

        file_put_contents($cacheFile, $cache);

        return true;
    }
615311
public function set($key, $value, $ttl = null)
	{
		return $this->_set($key, $value, $ttl, false);
	}
784833
public static function set($key, $value, int $ttl = null, array $tags = [])
    {
        $cache = self::getCacheService()->user();
        $item = $cache->getItem(self::key($key));
        $item->set($value);
        if ($ttl) {
            $item->expiresAfter($ttl);
        }
        if ($tags && $item instanceof CacheItem) {
            $item->tag($tags);
        }
        self::getCacheService()->user()->save($item);
    }
37157
public function set($key, $value, $ttl = null) {
        $key = md5($key);
        // remove oldest item only if reached limit
        if ($this->maxSize) {
            if (count($this->items) >= $this->maxSize) {
                if (!isset($this->items[$key])) {
                    array_shift($this->items);
                }
            }
        }

        $this->items[$key] = $value;
    }