Save an item to cache.

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

@since 3.0.0

@return object
978821
public function saveItem($key, $value, $ttl = null)
    {
        $cache = [
            'start' => time(),
            'ttl'   => ($ttl !== null) ? (int) $ttl : $this->ttl,
            'value' => $value,
        ];
        if ($cache['ttl'] != 0) {
            $this->redis->set($key, json_encode($cache), $cache['ttl']);
        } else {
            $this->redis->set($key, json_encode($cache));
        }

        return $this;
    }
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;
    }
242514
public function set($key, $value, $ttl)
    {
        $file = array(
            'key'   => $key,
            'value' => serialize($value),
            'ttl'   => $ttl,
            'ctime' => time(),
        );

        if ($this->isSafe() && !empty($key)) {
            return (bool) file_put_contents($this->getFilename($key), serialize($file));
        }

        return false;
    }
1208366
public function set($key, $value, $ttl = null)
    {
        if ($ttl) {
            $ttl = $ttl->getTimestamp() - (new \DateTime('now', new \DateTimeZone('UTC')))->getTimestamp();
            $this->getRedis()->setex($key, $ttl, $value);
        } else {
            $this->getRedis()->set($key, $value);
        }

        return $this;
    }
814053
public function set($key, $value, $ttl = 0)
    {
        $this->cache[$key] = new Item($value);
        return true;
    }
521794
public function set($entry, $value, $ttl = false)
    {
        $setCallback = function ($setSuccess, $cache) use ($entry, $value, $ttl) {
            return $setSuccess || $cache->set($entry, $value, $ttl);
        };
        return array_reduce($this->caches, $setCallback, false);
    }
803222
public function put($key, $value, $ttl = null)
    {
        $k = $this->hash($key);
        if (isset($this->cache[$k])) {
            $item = $this->cache[$k];
            $item->setValue($value);
            if ($ttl !== null) {
                $item->expire = microtime(true) + $ttl;
            }
            return $item;
        }
        $item = new Item($value);
        if ($ttl !== null) {
            $item->expire = microtime(true) + $ttl;
        }
        $this->cache[$k] = $item;
        $s = sizeof($this->cache);
        if ($s > $this->maxCacheSize + $this->capWindow) {
            uasort($this->cache, $this->sorter);
            for (; $s > $this->maxCacheSize; --$s) {
                array_pop($this->cache);
            }
        }
        return $item;
    }
1326507
public function append($key, $value, $ttl=null)
    {
        return $this->getStorage()->append($key, $value, $ttl);
    }
1105002
public function set($key, $value, $ttl)
    {
        if ($value === false) {
            throw new InvalidValueException(['`:key` key cache value can not `false` bool value', 'key' => $key]);
        } elseif (is_scalar($value) || $value === null) {
            if (is_string($value) && $value !== '' && $value[0] !== '{' && $value[0] !== '[') {
                $data = $value;
            } else {
                $data = json_encode(['_wrapper_' => $value], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
            }
        } elseif (is_array($value) && isset($value['_wrapper_'])) {
            $data = json_encode(['_wrapper_' => $value], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
        } else {
            $data = json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
        }

        if ($data === false) {
            throw new InvalidValueException([
                '`:key` key cache value json_encode failed: `:code` `:message`',
                'key' => $key,
                'code' => json_last_error(),
                'message' => json_last_error_msg()
            ]);
        }

        $this->do_set($key, $data, $ttl);
    }
592877
public function set($key, $value, $ttl = null)
	{
	    if (!$this->connect()) {
	        return null;
	    }
	    //\Wslim\Ioc::logger('cache')->debug(sprintf('set: %s %s', $key, print_r($value, true)));
	    
		$oldKey = $key;
		
		$key = $this->formatKey($key);
		$value = $this->encodeValue($value);		
		$ttl = $ttl ? $ttl : $this->options['ttl'];

		$result = $this->driver->set($key, $value, MEMCACHE_COMPRESSED, $ttl);
		
		return $result;
	}
782251
protected function pack($key, $value, $ttl = 0)
    {
        $content = array(
            'key' => $key,
            'time' => time(),
            'ttl' => $ttl,
            'value' => $value
        );

        return $content;
    }
237802
public function set($key, $value, $ttl = null)
    {
        if (null == $ttl) {
            return $this->redis->set($key, $value);
        }

        if (null == $ttl) {
            return $this->redis->set($key, $value);
        }

        if (!is_int($ttl) || 0 >= $ttl) {
            throw new \InvalidArgumentException('The time to live parameter must be an integer and greater than zero.');
        }

        return $this->redis->setex($key, $ttl, $value);
    }
247703
public function set($key, $data, $ttl)
    {
        $this->ttl = $ttl;

        $filename = $this->cacheDir . DIRECTORY_SEPARATOR . $this->processKey($key);

        return $this->safelyWriteData($filename, 'w', serialize($data));
    }
309292
public function store($key, $value, $ttl = self::DEFAULT_TTL) {
        $this->storage[$key]      =   array('value' => $value, 'expires' => ($ttl) ? time() + $ttl : 0);
        return $value;
    }
1255778
public function set($key, $value, $ttl)
    {
        if (!$this->memcached->set($key, $value, $ttl)) {
            // If set() returns false, that means the key already exists,
            return $this->memcached->replace($key, $value, $ttl);
        } else {
            // set() returned true, so the key has been set successfully
            return true;
        }
    }
661269
public function setWithTtl($key, $value, $ttl) {
        if (is_resource($value))
            return false;

        if ($ttl != 0 && $ttl > 2592000) {
            $ttl -= time();
        }
        if ($ttl <= 0)
            return true;

        $key = $this->getUsedKey($key);
        $res = $this->_connection->set($key, $this->esc($value));

        if ($res !== 'OK') {
            return false;
        }

        return ($this->_connection->expire($key, $ttl) == 1);
    }
738208
private function add($key, $value, $ttl = 2592000)
    {
        $res = self::$memcached->add(CFG_DOMAIN . $key, $value, $ttl);
        return $res;
    }