Set a cache value
@param string $key
@param mixed $value
@param integer $ttl (optional) default 86400
@return boolean
964315
public function set($key, $value, $ttl = self::DEFAULT_TTL)
    {
        if (!$this->hasApc) {
            // @codeCoverageIgnoreStart
            return false;
            // @codeCoverageIgnoreEnd
        }

        return apc_store($key, $value, $ttl);
    }
738208
private function add($key, $value, $ttl = 2592000)
    {
        $res = self::$memcached->add(CFG_DOMAIN . $key, $value, $ttl);
        return $res;
    }
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;
    }
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);
	}
674691
protected function doSet(string $key, $value, int $ttl = 0)
	{
		if ($ttl > 0) {
			$ttl = \time() + $ttl;
		}

		$filename = $this->getFilename($key);
		$code = '<?php return ';

		if ($ttl > 0) {
			$code .= '(time() > ' . $ttl . ') ? null : ';
		}

		$code .= \var_export($value, true) . ';';

		return $this->writeFile($filename, $code);
	}
652637
protected function setToCache($cacheKey, $value, $ttl = null)
    {
        // Seralize as JSON to ensure array etc can be stored
        $value = Convert::raw2json($value);

        return $this->getCache()->set($cacheKey, $value, $ttl);
    }
1074948
public function write($key, $value, $ttl = 0)
    {
        $this->redis->set($this->prefix . $key, is_numeric($value) ? $value : serialize($value));
        if ($ttl != 0) {
            $this->redis->expire($this->prefix . $key, $ttl);
        }
        return true;
    }
458834
public function setItem(string $key, $value, $ttl = 0): bool
    {
        if (
            !$this->adapter instanceof iAdapter
            ||
            !$this->serializer instanceof iSerializer
        ) {
            return false;
        }

        $storeKey = $this->calculateStoreKey($key);
        $serialized = $this->serializer->serialize($value);

        // update static-cache, if it's exists
        if (\array_key_exists($storeKey, self::$STATIC_CACHE)) {
            self::$STATIC_CACHE[$storeKey] = $value;
        }

        if ($ttl) {
            if ($ttl instanceof \DateInterval) {
                // Converting to a TTL in seconds
                /** @noinspection PhpUnhandledExceptionInspection */
                $ttl = (new \DateTimeImmutable('now'))->add($ttl)->getTimestamp() - \time();
            }

            // always cache the TTL time, maybe we need this later ...
            self::$STATIC_CACHE_EXPIRE[$storeKey] = ($ttl ? (int) $ttl + \time() : 0);

            return $this->adapter->setExpired($storeKey, $serialized, $ttl);
        }

        return $this->adapter->set($storeKey, $serialized);
    }
314171
public static function set($key, $data, $ttl = self::TTL_NO_EXPIRY, $tags = [])
    {
        if (!$cache = self::getInstance()) {
            return false;
        }

        $key = self::prepare($key);
        try {
            $item = $cache->getItem($key);
            $item->set($data);

            if (self::TTL_NO_EXPIRY !== $ttl) {
                $item->expiresAfter($ttl);
            }

            if (!empty($tags)) {
                $item->setTags($tags);
            }

            return $cache->save($item);
        } catch (InvalidArgumentException $e) {
            // something going wrong
            Logger::error($e->getMessage());
        }

        return false;
    }
1206537
public function set($key, $val, $ttl = null)
    {
        $this->throwInvalidStringArgumentException($key);

        $this->cache[$key] = $val;

        return true;
    }
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;
    }
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;
    }
1033146
public function saveItem($key, $value, $ttl = null)
    {
        $cache = [
            'start' => time(),
            'ttl'   => ($ttl !== null) ? (int) $ttl : $this->ttl,
            'value' => $value,
        ];

        $this->memcached->set($key, $cache, $cache['ttl']);

        return $this;
    }
809051
function set($key,$val,$ttl=0) {
		$fw=Base::instance();
		if (!$this->dsn)
			return TRUE;
		$ndx=$this->prefix.'.'.$key;
		if ($cached=$this->exists($key))
			$ttl=$cached[1];
		$data=$fw->serialize([$val,microtime(TRUE),$ttl]);
		$parts=explode('=',$this->dsn,2);
		switch ($parts[0]) {
			case 'apc':
			case 'apcu':
				return call_user_func($parts[0].'_store',$ndx,$data,$ttl);
			case 'redis':
				return $this->ref->set($ndx,$data,$ttl?['ex'=>$ttl]:[]);
			case 'memcache':
				return memcache_set($this->ref,$ndx,$data,0,$ttl);
			case 'memcached':
				return $this->ref->set($ndx,$data,$ttl);
			case 'wincache':
				return wincache_ucache_set($ndx,$data,$ttl);
			case 'xcache':
				return xcache_set($ndx,$data,$ttl);
			case 'folder':
				return $fw->write($parts[1].
					str_replace(['/','\\'],'',$ndx),$data);
		}
		return FALSE;
	}
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;
	}
946393
private function setToCache(string $key, $value, $ttl = null): void
    {
        $params = func_get_args();

        // Use default TTL if none is provided
        if ($this->cacheTTL && $ttl === null) {
            array_push($params, $this->cacheTTL);
        }

        call_user_func_array([$this->cache(), 'set'], $params);
    }
1176534
private function setToCache($key, $value, $ttl = 0)
    {
        if (!$this->cache()) {
            return;
        }

        $params = func_get_args();

        // Use default TTL if none is provided
        if ($this->cacheTTL && func_num_args() < 3) {
            array_push($params, $this->cacheTTL);
        }

        call_user_func_array([$this->cache(), 'set'], $params);
    }