Create a PHP script returning the cached value

@param mixed    $value
@param int|null $ttl
@return string
1397
public function createScript($value, ?int $ttl): string
    {
        $macro = var_export($value, true);

        if (strpos($macro, 'stdClass::__set_state') !== false) {
            $macro = preg_replace_callback("/('([^'\\\\]++|''\\.)')|stdClass::__set_state/", $macro, function($match) {
                return empty($match[1]) ? '(object)' : $match[1];
            });
        }

        return $ttl !== null
            ? "<?php return time() < {$ttl} ? {$macro} : false;"
            : "<?php return {$macro};";
    }
941394
public function set($name, $value, $ttl = 0){

		$name = trim($name);

		if($name == ''){

			throw new CacheException('Cache-entry name cannot be empty');
		}

		$name = $this->_prependPrefix($name);

		if(is_resource($value)){

			throw new CacheException('Cannot cache values of type "resource"');
		}

		if(!$this->validateValueSize($value)){

			ExceptionHandler::notice("Value in $name is too big to be stored in memcache.");
		}

		// A 30 day+ TTL is interpreted as a timestamp by memcached

		if($ttl > 2592000){

			$ttl = time() + $ttl;
		}

		// Name cannot be longer than 250 characters

		assert('strlen($name) <= 250');
		if(strlen($name) > 250) return false;

		$result = $this->_Memcache->set($name, $value, 0, $ttl);

		if($result === false && !Memcache::isConnected($this->_Memcache)){

			throw new CacheException("Failed to set '$name', Memcache appears
				to be disconnected!?");
		}

		return $result;
	}
788545
public function set(string $key, $value, int $ttl = null): void
    {
        $keyMD5 = md5($key);
        $key = $this->keyPrefix . substr($keyMD5, 0, 3) . '/' . substr($keyMD5, 3) . '.2';
        $this->dataRepository->setValue($key, gzcompress(serialize([$ttl > 0 ? time() + $ttl : 0, $value])));
    }
258773
public function set($key, $value, $ttl = 0)
    {
        $ttl = $this->fromDefaultTtl($ttl);

        if ($ttl >= 0) {
            $this->memcached->set($key, $value);

            if ($ttl > 0) {
                $this->memcached->touch($key, \time() + $ttl);
            }

            $this->setChain($key, $value, $ttl);
        }

        return $this;
    }
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(),
        ));
    }
983718
public function set($key, $value, $ttl)
    {
        $filename = $this->_hash(array($key));

        return (bool) $this->_write($filename, $value, null, $ttl);
    }
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);
    }
950501
public function save( $id, $value, $ttl = 0 ) {

		$this->count++;
		$this->cacheInserts++;

		if ( $this->contains( $id ) ) {
			$this->count--;
			$this->moveToMostRecentlyUsedPosition( $id );
		} elseif ( $this->count > $this->maxCacheCount ) {
			$this->count--;
			reset( $this->cache );
			unset( $this->cache[ key( $this->cache ) ] );
		}

		$this->cache[ $id ] = $value;
		$this->ttl[ $id ] = $ttl > 0 ? microtime( true ) + $ttl : 0;
	}
185057
protected function insertToDatabase($key, $value, $ttl = 0)
    {
        $value = $this->storageDataStructure($value);

        $calculatedTtl = $this->fromDefaultTtl($ttl);
        $calculatedTtl = new DateTime(\date('Y-m-d H:i:s', $this->getCalculatedTtl($calculatedTtl)));

        $databaseValue = $this->getFromDatabase($key);
        if (false === empty($databaseValue)) {
            $databaseValue[self::CACHE_VALUE] = $value;
            $this->updateToDatabase($key, $databaseValue, $calculatedTtl);
            return $this;
        }

        $stmt = $this->connection->prepare(
            \sprintf(
                'INSERT INTO %s(id,%s,%s,%s) VALUES(%s,%s,%s,%s)',
                $this->cacheTableName,
                self::TABLE_CACHE_ID,
                self::TABLE_CACHE_VALUE,
                self::TABLE_CACHE_TTL,
                self::SPHINX_ID_PLACEHOLDER,
                self::QUERY_ID_PLACEHOLDER,
                self::QUERY_VALUE_PLACEHOLDER,
                self::QUERY_TTL_PLACEHOLDER
            )
        );

        $sphinxId = (int) $this->connection->lastInsertId()+1;

        $stmt->bindParam(self::SPHINX_ID_PLACEHOLDER, $sphinxId, PDO::PARAM_STR);
        $stmt->bindParam(self::QUERY_ID_PLACEHOLDER, $key, PDO::PARAM_STR);
        $stmt->bindParam(self::QUERY_VALUE_PLACEHOLDER, $value, PDO::PARAM_STR);
        $calculatedTtl = $calculatedTtl->format('Y-m-d H:i:s');
        $stmt->bindParam(self::QUERY_TTL_PLACEHOLDER, $calculatedTtl, PDO::PARAM_STR);
        $stmt->execute();

        return $this;
    }
1321644
protected function createCacheValue($key, $value, $ttl = null)
    {
        $created = time();

        return array(
            'created' => $created,
            'key' => $key,
            'value' => $value,
            'ttl' => $ttl,
            'expires' => ($ttl) ? $created + $ttl : null
        );
    }
584756
public function set($key, $value, $ttl = null)
    {
        $values = $this->readFileContents();

        $values[$key] = [];

        $values[$key][self::VALUE] = $value;
        $values[$key][self::TTL] = $ttl;
        $values[$key][self::CREATE_TIME] = time();

        return $this->writeFileContents($values);
    }
621782
public function set($key, $value, $ttl = null)
    {
        $this->values[$key] = [];

        $this->values[$key][static::VALUE] = $value;
        $this->values[$key][static::TTL] = $ttl;
        $this->values[$key][static::CREATE_TIME] = time();

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

        if ($ttl >= 0) {
            $calculatedTtl = $this->getCalculatedTtl($ttl);
            $data          = $this->buildDataCache($value, $calculatedTtl);
            \file_put_contents($this->getFilenameFromCacheKey($key), $data);
            $this->setChain($key, $value, $ttl);
        }

        return $this;
    }
1207455
public function set($key, $value, $ttl = 2592000)
    {
        if (!self::$instance) {
            self::getInstance();
        }

        $res = NULL;
        // Try to update existing
        if ($this->exists($key)) {
            $res = self::$memcached->set(CFG_DOMAIN . $key, $value, $ttl);
        } else {
            // Set new
            $res = $this->add($key, $value, $ttl);
        }
        return $res;
    }
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);
	}
782251
protected function pack($key, $value, $ttl = 0)
    {
        $content = array(
            'key' => $key,
            'time' => time(),
            'ttl' => $ttl,
            'value' => $value
        );

        return $content;
    }
96732
public function set($key, $value, $ttl = null)
  {
    $success = \apcu_store( $key, $value, (\is_null($ttl) ? 0 : (int) $ttl) );

    return $success;
  }