Create a new instance with the headers to enable client caching.

@param string $since a valid time since the response text has not been modified
@param string $time a valid time for cache expiry
@return static
427491
public function withCache($since, $time = '+1 day')
    {
        if (!is_int($time)) {
            $time = strtotime($time);
        }

        return $this->withHeader('Date', gmdate('D, j M Y G:i:s ', time()) . 'GMT')
            ->withModified($since)
            ->withExpires($time)
            ->withSharable(true)
            ->withMaxAge($time - time());
    }
989844
public function expiresAfter($time)
    {
        $this->expiration = new \DateTime();
        if (is_int($time)) {
            if ($time < 0) {
                $time = new \DateInterval('PT' . abs($time) . 'S');
                $time->invert = 1;
            } else {
                $time = new \DateInterval('PT' . $time . 'S');
            }
        }
        $this->expiration->add($time);
        $this->changed = true;
        return $this;
    }
544904
public final function expiresAfter($time)
   {
       $this->timeToLive = $time instanceof DateInterval
                         ? (new DateTime())->add($time)->getTimestamp()
                         - time()
                         : (int) $time;
       return $this;
   }
1058484
public function setTime(DateTime $time = null)
    {
        $timestamp = $time ? $time->getTimestamp() : null;

        $this->session->put($this->timePersistenceKey, $timestamp);

        if ($time) {
            $this->setState(static::HISTORY);
        }

        return $this;
    }
413778
public static function create($host, $cacheDir = null, EventManager $eventManager = null)
    {
        $cache = $cacheDir ?: sys_get_temp_dir();
        $client = ClientBuilder::create()
            ->addConnection('default', $host)
            ->build();

        return new self($client, $cache, $eventManager);
    }
860800
public function cache(int $minute = 1440): CacheService
    {
        if (empty($this->cache)) {
            $this->cache = new CacheService();
            $this->cache->setRepository($this);
        }

        return $this->cache->setCacheMinute($minute);
    }
421022
public static function create($fid, $timestamp = null)
  {
    /**
     * @var $payload MarkDatePayload
     */
    $payload = parent::create($fid);
    $payload->timestamp = $timestamp;
    return $payload;
  }
1319705
public static function get_instance_for_cache(\cache_definition $definition) {
        if (is_null(self::$instance)) {
            self::$instance = new time_last_message_between_users();
        }
        return self::$instance;
    }
1268458
public function cache( $time = null, $e_tag = null )
	{
		if( $time instanceof \DateTime )
		{
			$time = $time->getTimestamp() - time();
		}
		else if( null === $time )
		{
			$time = 3600*24*7; // default cache 7 day
		}
		else
		{
			$time = (int) $time;
		}

		// Invalid timeout
		if( $time < 1 )
		{
			return $this;
		}

		$this->header('Cache-Control', 'public, max-age=' . $time);
		if( null !== $e_tag )
		{
			$this->header("ETag", $e_tag);
		}

		return $this;
	}
1321183
public static <K, V> TimedCache<K, V> newTimedCache(long timeout){
		return new TimedCache<K, V>(timeout);
	}
1149904
protected function getInterval($fromTime, $toTime = null)
    {
        $fromTime = new DateTime($this->normalizeDate($fromTime));
        $toTime   = new DateTime($this->normalizeDate($toTime));

        return $fromTime->diff($toTime);
    }
714691
public static function createFromEndAndDuration(Date $end, Duration $duration)
    {
        return static::create($end->sub($duration), $end);
    }
824373
private static function _createDateTime($time = null, $tz = null): \DateTimeImmutable
    {
        if (!isset($time)) {
            $time = 'now';
        }
        if (!isset($tz)) {
            $tz = date_default_timezone_get();
        }
        try {
            $dt = new \DateTimeImmutable($time, self::_createTimeZone($tz));
            return self::_roundDownFractionalSeconds($dt);
        } catch (\Exception $e) {
            throw new \RuntimeException(
                "Failed to create DateTime: " .
                     self::_getLastDateTimeImmutableErrorsStr(), 0, $e);
        }
    }
782575
public function expiresAfter($time): CacheItemInterface
    {
        if (null === $time) {
            $this->expiry = $this->defaultLifetime > 0 ? time() + $this->defaultLifetime : null;
        } elseif ($time instanceof \DateInterval) {
            $date = \DateTime::createFromFormat('U', (string) time());
            if ($date === false) {
                throw new InvalidArgumentException('Invalid time');
            }
            $this->expiry = (int) $date->add($time)->format('U');
        } elseif (is_int($time)) {
            $this->expiry = $time + time();
        } else {
            throw new InvalidArgumentException(sprintf(
                'Expiration date must be an integer, a DateInterval or null, "%s" given',
                is_object($time) ? get_class($time) : gettype($time)
            ));
        }

        return $this;
    }
676638
public function expires($time)
    {
        if (!empty($time) && is_string($time) && !$timestamp = strtotime($time)) {
            throw new \Ergo\Routing\Exception("Invalid expiry time: $timestamp");
        } else if (is_numeric($time)) {
            $timestamp = $time;
        } else if ($time == false) {
            return $this;
        }

        $this->addHeader('Expires', date('r', $timestamp));

        return $this;
    }
757893
public function set_time($time = null) {
        if (empty($time)) {
            $this->time = time();
        } else {
            $this->time = $time;
        }

        return $this;
    }
951171
public function createCacheElement($key, $callback, $params, $timeout)
    {
        if(isset($this->datas[$key]))
            return $this->datas[$key];

        $upToDate = true;
        $data     = null;

        if (file_exists($this->cacheDir . $key . '.cache')) {
            try {
                /** @var Cache $data */
                $data = unserialize(file_get_contents($this->cacheDir . '/' . $key . '.cache'));

                if ($data->time + $timeout < time()){
                    $upToDate = false;
                }
            } catch (\Exception $e) {
                $upToDate = false;
            }
        } else {
            $upToDate = false;
        }

        if ($upToDate && $data != null) {
            $this->datas[$key] =  $data->data;
            return $this->datas[$key];
        } else {
            $data = new Cache();

            $data->data = call_user_func_array($callback, $params);
            $data->time = time();
            file_put_contents($this->cacheDir . '/' . $key . '.cache', serialize($data));
            $this->datas[$key] = $data->data;
            return $this->datas[$key];
        }
    }