Save an item to cache.

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

@since 3.0.0

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

        apcu_store($key, $cache, $cache['ttl']);

        return $this;
    }
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);
    }
964315
public function set($key, $value, $ttl = self::DEFAULT_TTL)
    {
        if (!$this->hasApc) {
            // @codeCoverageIgnoreStart
            return false;
            // @codeCoverageIgnoreEnd
        }

        return apc_store($key, $value, $ttl);
    }
173202
public function do_set($key, $value, $ttl)
    {
        $redis = is_object($this->_redis) ? $this->_redis : $this->_getRedis();
        $redis->set($this->_prefix . $key, $value, $ttl);
    }
539488
public function set($key, $value, $ttl = self::DEFAULT_TTL)
    {
        $md5 = md5($key);
        $folderPath = $this->getFolderPathFromMd5($md5);
        $create = $this->helper->createPath($this->path, $folderPath);
        if (!$create) {
            return false;
        }
        $basePaths = $this->path . self::DS . $folderPath;
        $path = $basePaths . self::DS . $this->prefix . $md5;

        $handle = fopen($path, 'w');
        if ($handle) {
            $data = time() + $ttl . PHP_EOL . serialize($value);
            $success = fwrite($handle, $data);
            return ($success !== false);
        }

        // @codeCoverageIgnoreStart
        return false;
        // @codeCoverageIgnoreEnd
    }
906339
public function create($key, $value, $ttl = 0)
    {
        return $request = $this->set($key, $value, $ttl, ['prevExist' => 'false']);
    }
644117
public function set($key, $value, $ttl = 60, $raw = false)
    {
        if ($raw !== true) {
            $value = [$value, time(), $ttl];
        }

        if (get_class($this->memcached) === 'Memcached') {
            return $this->memcached->set($key, $value, $ttl);
        } elseif (get_class($this->memcached) === 'Memcache') {
            return $this->memcached->set($key, $value, 0, $ttl);
        }

        return false;
    }
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);
    }
141021
public function store($key, $value, $ttl = self::DEFAULT_TTL) {
        apc_store($key, $value, (int) $ttl);
        return $value;
    }
826240
public function do_set($key, $value, $ttl)
    {
        $context = $this->_context;

        $context->data[$key] = ['deadline' => time() + $ttl, 'data' => $value];
    }
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;
    }
867533
public function set($key, $value, $ttl)
    {
        // if no ttl is provided use the default
        if (is_null($ttl)) $ttl = $this->config->get('expiration');
        return (bool) $this->redis->pipeline(function($pipe) use ($key, $value, $ttl) {
            $pipe->set($key, $value);
            $pipe->expire($key, $ttl);
        });
    }
615311
public function set($key, $value, $ttl = null)
	{
		return $this->_set($key, $value, $ttl, false);
	}
745583
public function add($key, $value, $ttl = null)
    {
        if ($ttl !== null) {
            if ($this->getSeconds($ttl) <= 0) {
                return false;
            }

            // If the store has an "add" method we will call the method on the store so it
            // has a chance to override this logic. Some drivers better support the way
            // this operation should work with a total "atomic" implementation of it.
            if (method_exists($this->store, 'add')) {
                $seconds = $this->getSeconds($ttl);

                return $this->store->add(
                    $this->itemKey($key), $value, $seconds
                );
            }
        }

        // If the value did not exist in the cache, we will put the value in the cache
        // so it exists for subsequent requests. Then, we will return true so it is
        // easy to know if the value gets added. Otherwise, we will return false.
        if (is_null($this->get($key))) {
            return $this->put($key, $value, $ttl);
        }

        return false;
    }
817961
public function set($key, $value, $ttl = null)
    {
        if ($this->enabled()) {
            return $this->manager->set($key, $value, $ttl);
        }

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

        return $content;
    }
66227
public function set($key, $value, $ttl = null)
    {
        $ttl = is_null($ttl) ? $this->ttl : $ttl;

        return $this->client->set($this->getKey($key), $value, $ttl);
    }