Sets the cache data

@param string $key
@param mixed $value
@param integer $ttl Time to live in seconds
@param integer $time Current timestamp
@return \Krystal\Cache\FileEngine\ArrayCache
502956
public function set($key, $value, $ttl, $time)
    {
        $this->data[$key] = array(
            self::CACHE_PARAM_VALUE => $value,
            self::CACHE_PARAM_CREATED => $time,
            self::CACHE_PARAM_TTL => $ttl
        );

        return $this;
    }
1192925
public function set($key, $value, $ttl = 2592000)
    {
        if (!self::$instance) {
            self::getInstance();
        }
        $res = self::$Memcache->set(CFG_DOMAIN . $key, $value, MEMCACHE_COMPRESSED, $ttl);

        return $res;
    }
47309
protected function setCacheFileContent($key, $content, $ttl = 0)
    {
        $result = true;
        $filepath = $this->getCacheFilePath($key);
        $content = serialize($content);
        if (file_put_contents($filepath, $content) === false) {
            $result = false;
        }

        if ($result !== false) {
            $ttl = $ttl + time();
            touch($filepath, $ttl);
        }

        return $result;
    }
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;
    }
1268037
public function set($key, $value, $ttl)
    {
        if (!$this->safe) {
            return false;
        }

        return apc_store($key, $value, $ttl);
    }
1210885
public function set($key, $value, $ttl = null)
    {
        $this->adapter->saveItem($key, $value, $ttl);

        return $this;
    }
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);
    }
1284496
public function put($key, $value, $ttl = null)
    {
        if (is_array($key)) {
            return $this->putMany($key, $value);
        }

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

        $seconds = $this->getSeconds($ttl);

        if ($seconds <= 0) {
            return $this->delete($key);
        }

        $result = $this->store->put($this->itemKey($key), $value, $seconds);

        if ($result) {
            $this->event(new KeyWritten($key, $value, $seconds));
        }

        return $result;
    }
262286
public function set($key, $value, $timeToLive = null) {
		$filename = $this->getFileName($key);
		//$this->log->trace("Storing value in cache: key '$key', value '".var_export($value, true)."'");
		if ($this->log) {
			if ($this->log instanceof LoggerInterface) {
				$this->log->info("Storing value in cache: key '{key}'", array('key'=>$key));
			} else {
				$this->log->trace("Storing value in cache: key '$key'");
			}
		}

        $oldUmask = umask(0);

		if (!is_writable($filename)) {
			if (!file_exists($this->getDirectory())) {
				mkdir($this->getDirectory(), 0777, true);
			}
		}
		
		if ($timeToLive == null) {
			if (empty($this->defaultTimeToLive)) {
				$timeOut = 0;
			} else {
				$timeOut = time() + $this->defaultTimeToLive;
			}
		} else {
			$timeOut = time() + $timeToLive;
		}

		$data = array(
			'lifetime'  => $timeOut,
			'data'      => $value
		);

        $serializeData = serialize($data);
        if(strpos($serializeData, 'r:') !== false || (is_object($value) && !method_exists($value, '__set_state'))){
            $code   = sprintf('<?php return unserialize(%s);', var_export($serializeData, true));
            file_put_contents($filename, $code);
        }else{
            $data  = var_export($data, true);
            $code   = sprintf('<?php return %s;', $data);
            file_put_contents($filename, $code);
        }

        // Cache is shared with group, not with the rest of the world.
        chmod($filename, 0660);

        umask($oldUmask);
	}
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;
    }
194925
public function do_set($key, $value, $ttl)
    {
        /** @var \ManaPHP\DbInterface $db */
        $db = $this->_di->getShared($this->_db);

        $hash = md5($key);

        if ($db->query($this->_source)->whereEq('hash', $hash)->exists()) {
            $db->update($this->_source, ['value' => $value, 'ttl' => $ttl, 'expired_time' => time() + $ttl], ['hash' => $hash]);
        } else {
            $db->insert($this->_source, ['hash' => $hash, 'key' => $key, 'value' => $value, 'ttl' => $ttl, 'expired_time' => time() + $ttl]);
        }
    }
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;
        }
    }
782251
protected function pack($key, $value, $ttl = 0)
    {
        $content = array(
            'key' => $key,
            'time' => time(),
            'ttl' => $ttl,
            'value' => $value
        );

        return $content;
    }
1362402
public function set($key, $data, $ttl = 3600)
    {
        if (empty($this->memcache)) {
            return false;
        }

        $key = $this->processKey($key);

        $compress = !empty($this->compress) ? MEMCACHE_COMPRESSED : 0;

        return $this->memcache->set($key, $data, $compress, $ttl);
    }
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;
    }
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);
    }
1036433
public function set($key, $data, $ttl = null)
    {
        if ($ttl) {
            $now = new \DateTime('now', new \DateTimeZone('UTC'));
            $expire = (int) $now->format('U') + $ttl;
        } else {
            $expire = 0;
        }

        $entry = array(
            'expire' => $expire,
            'value' => $data
        );

        $this->storage[$key] = $entry;

        return true;
    }