Set the TTL using one of the strategies

@param int    $expiration
@param string $contents
@param string $cacheFile
@return string  The (modified) contents
488080
protected function setTtl($expiration, $contents, $cacheFile)
    {
        switch ($this->ttlStrategy) {
            case 'embed':
                $contents = ($expiration ?? PHP_INT_MAX) . "\n" . $contents;
                break;
            case 'file':
                if (isset($expiration)) {
                    file_put_contents("$cacheFile.ttl", $expiration);
                }
                break;
            case 'mtime':
                // nothing
                break;
        }

        return $contents;
    }
1324807
public function setCache(\Psr\SimpleCache\CacheInterface $cache, $key, $ttl = 86400)
    {
        $this->cache = $cache;
        $this->cacheKey = $key;
        $this->cacheTime = $ttl;

        if (empty($this->cacheKey))
        {
            $this->cacheKey = 'concatenate-'.md5(serialize($this));
        }

        return $this;
    }
931030
public function save($ttl = 0)
	{
		$ttl = ($ttl)?:$this->ttl;
		if (empty($this->file)) {
			trigger_error('Unable to save. No file specified.');
			return false;
		}
		if(is_null($this->content)) {
			trigger_error(sprintf('Unable to save. Contents of file `%s´ is NULL.',$this->file));
			return false;
		}
		if ($this->changed) {
			$this->fs->write($this->file, (string) $this->content);
			if ($this->f3->get('CACHE')) {
				$cache = \Cache::instance();
				$cacheHash = $this->getCacheHash($this->file);
				if ($this->ttl)
					$cache->set($cacheHash,$this->content,$this->ttl);
				elseif ($cache->exists($cacheHash))
					$cache->clear($cacheHash);
			}
		}
		$this->changed = false;
		$this->metaHandle->save($this->file,$this->meta,$ttl);
		return true;
	}
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;
    }
1333420
public function setMulti($items, $expiration = 0)
    {
        return $this->memcached ? $this->memcached->setMulti($items, $expiration) : false;
    }
1213661
public function write($key, $value, $expire = null) 
    {
        if (!$this->enabled) {
            return ;
        }

        if ($expire === null) {
            $expire = $this->expire;
        }
        
        $value = serialize($value);
        $cachePath = $this->getCachePath($key);
        
        $this->stats['execTimes'] ++;
        $this->stats['writeTimes'] ++;
        $this->stats['writeSize'] += strlen($value)/1024;
            
        try {            
            $this->waitUnlock($key);
            $this->lock($key);
            $set = $this->obj->set($cachePath, $value);
            $this->obj->setTimeout($cachePath, $expire);
            $this->unlock($key);
        } catch (\wf\cache\Exception $e) {
            $this->unlock($key);
            throw $e;
        }
    }
28932
public function store(Memento\Key $key, $value, $expires = null, $ttl = null)
    {
        $this->__connect($key);

        $hash = null;

        // if no expires specified use default of 5 minutes
        if (!is_numeric($expires)) {
            $expires = self::DEFAULT_EXPIRES;
        }

        // ttl is when the cache is actually okay for deletion
        if (!is_numeric($ttl)) {
            $ttl = $expires;
        }

        // convert to absolute time
        $expires = $expires + time();
        $ttl = $ttl + time();

        // handle arguments based on group or single key
        if ($this->groupKey) {
            $hash = array(
                $this->groupKey->getKey(),
                Memento\Hash::FIELD_VALID,
                serialize(true),
                $key->getKey(),
                serialize($value),
                Memento\Hash::FIELD_EXPIRES,
                $expires,
                Memento\Hash::FIELD_TTL,
                $ttl,
            );
        } else {
            $hash = array(
                $key->getKey(),
                array(
                    Memento\Hash::FIELD_DATA  => serialize($value),
                    Memento\Hash::FIELD_VALID => serialize(true),
                    Memento\Hash::FIELD_EXPIRES  => $expires,
                    Memento\Hash::FIELD_TTL => $ttl,
                )
            );
        }

        if (!is_array($hash)) {
            return false;
        }

        if ($success = call_user_func_array(array($this->redis, 'hmset'), $hash)) {
            $this->setExpires($key, $ttl); // actual redis expires uses ttl value
        }

        return $success;
    }
42730
public function set($key, $value, $expire = null)
    {
        return $this->_master()->set($key, json_encode($value), $expire);
    }
431207
public function set($key, $value, $expireResolution = null, $expireTTL = null, $flag = null)
    {
        $expireResolution = strtolower($expireResolution);
        $expireTTL = strtolower($expireTTL);

        $condition = null;
        $ttl = 0;
        if (in_array($expireResolution, array('nx', 'xx'))) {
            $condition = $expireResolution;
            if ($expireTTL === 'ex') {
                $ttl = $flag;
            } elseif ($expireTTL === 'px') {
                $ttl = ceil($flag / 1000);
            }
        } else {
            if ($expireResolution === 'ex') {
                $ttl = $expireTTL;
            } elseif ($expireResolution === 'px') {
                $ttl = ceil($expireTTL / 1000);
            }
        }

        if ($condition === 'nx' && $this->doExists($key)) {
            return null;
        }
        if ($condition === 'xx' && !$this->doExists($key)) {
            return null;
        }

        $this->data[$key] = $value;
        if ($ttl > 0) {
            $this->expiring[$key] = $this->getTimestamp() + $ttl;
        }

        return 'OK';
    }
487176
public function setCacheFile(string $cacheFile) : Router
    {
        if ($cacheFile == '') {
            $this->cacheFile = false;

            return $this;
        }

        $spl    = new \SplFileInfo($cacheFile);
        $splDir = $spl->getPathInfo();
        if (! $splDir->isWritable()) {
            throw new \RuntimeException(
                'Cache file directory is not writable',
                E_WARNING
            );
        }
        if ($spl->getRealPath() && ! $spl->isFile()) {
            throw new \RuntimeException(
                sprintf(
                    'Cache file is not a file %s given',
                    $spl->getType()
                ),
                E_WARNING
            );
        }

        if (! $spl->getRealPath()) {
            $spl = new \SplFileInfo($splDir->getRealPath() . DIRECTORY_SEPARATOR . $spl->getBasename());
        }

        $this->cacheFile = $spl->__toString();
        unset($spl, $splDir);

        return $this;
    }
969261
public static function cacheHeaders($expires = '+1 hour')
    {
        if (!headers_sent()) {
            header('Cache-Control: private, max-age=3600');
            header('Pragma: public');
            header('Last-Modified: ' . date(DATE_RFC822, strtotime('-1 second')));
            header('Expires: ' . date(DATE_RFC822, strtotime($expires)));
        }
    }
1292060
public static function cache($expire = 3600, $last_modify = null) {
        $time    = time();
        $date    = gmdate('D, d M Y H:i:s', $time) . ' GMT';
        $headers = [
            'Age'           => $expire,
            'Date'          => $date,
            'Expires'       => gmdate('D, d M Y H:i:s', $time + $expire) . ' GMT',
            'Cache-Control' => 'public, must-revalidate, max-age=' . $expire,
            'Pragma'        => 'cache'
        ];
        if ($last_modify) {
            $ldate                    = @gmdate('D, d M Y H:i:s', $last_modify) . ' GMT';
            $headers['Last-Modified'] = $ldate;
        }
        foreach ($headers as $header => $val) {
            @header($header . ': ' . $val);
        }
    }
267023
public function set($key, $value, $expiration = 300) {

		$files = glob(Path :: get('cache-shared') . $this -> generateName($key));

		if(count($files) > 0 && true === is_array($files)) {
			
			foreach($files as $file) {
				
				$file = new File($file);
				$file -> delete();
			}
		}

		$cache = new File(Path :: get('cache-shared') . $this -> generateName($key, intval($expiration)));
		$cache -> create() -> append(serialize($value));

		return $this;
	}
279669
public function set($key, $value, $duration) {
        X::logger()->trace("CCache set $key expire in $duration");
        $file = $this->key2file($key);
        $content = array(
            'key'        => $key,
            'expiration' => $duration > 0 ? time() + $duration : 0,
            'data'       => $value,
        );
        $phpCode = '<?php return ' . Toolkit::compile($content) . ';';
        if (function_exists('opcache_invalidate')) {
            opcache_invalidate($file, true);
        }
        file_put_contents($file, $phpCode, LOCK_EX);
    }
766301
public function setExpire($expire)
	{
		if (null !== $expire)
		{
			$this->expire = $expire instanceof \DateTime ? $expire->getTimestamp() : (int) $expire;
		}
		else
		{
			$this->expire = $expire;
		}

		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);
    }
683428
private function setItem($key, $value, $time, $expire)
    {
        $cache_file = $this->createCacheFile($key);
        if ($cache_file === false) {
            return false;
        }

        $cache_data = array('data' => $value, 'time' => $time, 'expire' => $expire);
        $cache_data = json_encode($cache_data);

        $put_result = file_put_contents($cache_file, $cache_data);
        if ($put_result === false) {
            return false;
        }

        return true;
    }