Actual HTTP caching validation.

@param int    $mtime In seconds
@param string $etag

@return bool
176183
public static function isModified($mtime, $etag = '')
    {
        $modifiedSince = strtotime(preg_replace('/;.*$/', '', self::$IfModifiedSince));

        return !($modifiedSince >= $mtime || self::$IfNoneMatch == $etag);
    }
85014
public function addCachingHeaders($numberOfMinutes = 60, $mustRevalidate = true) {

        // Add cache control header if revalidate
        $numberOfSeconds = $numberOfMinutes * 60;
        $header = "Cache-Control: public, max-age=" . ($numberOfSeconds);
        if ($mustRevalidate)
            $header .= ", must-revalidate";

        header($header);

        // Add the Expires header.
        $expStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $numberOfSeconds) . " GMT";
        header($expStr);

        // Add the last modified header.
        $lastModified = "Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT";
        header($lastModified);

        header_remove("Pragma");

        $etag = '"' . filemtime(__FILE__) . '.' . date("U") . '"';
        header("ETag: $etag");


    }
347268
def _get_timestamp_cached(dirname_full, remove):
    
    if dirname_full not in TIMESTAMP_CACHE:
        mtime = _get_timestamp(dirname_full, remove)
        TIMESTAMP_CACHE[dirname_full] = mtime
    return TIMESTAMP_CACHE[dirname_full]
994923
public function cacheCallback($method, $args, Closure $callback, $time = null)
    {
        // Cache disabled, just execute query & return result
        if ($this->skippedCache() === true) {
            return call_user_func($callback);
        }

        // Use the called class name as the tag
        $tag = get_called_class();

        return self::getCacheInstance()->tags(['repositories', $tag])->remember(
            $this->getCacheKey($method, $args, $tag),
            $this->getCacheExpiresTime($time),
            $callback
        );
    }
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;
	}
159019
public static boolean isNotModified(Context context, long lastModified, String etag) {
        // First check etag. Important, if there is an If-None-Match header, we MUST not check the
        // If-Modified-Since header, regardless of whether If-None-Match matches or not. This is in
        // accordance with section 14.26 of RFC2616.

        final String browserEtag = context.header(HeaderNames.IF_NONE_MATCH);
        if (browserEtag != null) {
            // We check the given etag against the given one.
            // If the given one is null, that means that etags are disabled.
            return browserEtag.equals(etag);
        }

        // IF_NONE_MATCH not set, check IF_MODIFIED_SINCE
        final String ifModifiedSince = context.header(HeaderNames.IF_MODIFIED_SINCE);
        if (ifModifiedSince != null && lastModified > 0 && !ifModifiedSince.isEmpty()) {
            try {
                // We do a double check here because the time granularity is important here.
                // If the written date headers are still the same, we are unchanged (the granularity is the
                // second).
                return ifModifiedSince.equals(DateUtil.formatForHttpHeader(lastModified));
            } catch (IllegalArgumentException ex) {
                LoggerFactory.getLogger(CacheUtils.class)
                        .error("Cannot build the date string for {}", lastModified, ex);
                return true;
            }
        }
        return false;
    }
1190973
@Override
    public String etag(Locale locale) {
        String etag = etags.get(locale);
        if (etag == null) {
            // We don't have a stored etag, that means we don't have messages. We returns 0.
            // There is a potential race condition here:
            // We retrieve the etag get 0, but when we retrieve the messages, we get messages. The browser receives 0
            // as etag, which will not match the next request. It's should not be too critical as it will just send
            // the same content a second time.
            return "0";
        } else {
            return etag;
        }
    }
827333
private function setEtag(Request $request, Response $cachedResponse)
    {
        if ($etag = $cachedResponse->getHeader('ETag')) {
            $request->addHeader('If-None-Match', $etag);
        }
    }
18457
protected function getETag(CacheItemInterface $cacheItem)
    {
        $data = $cacheItem->get();

        foreach ($data['etag'] as $etag) {
            if (!empty($etag)) {
                return $etag;
            }
        }
    }
154610
private function setHttpCacheHeaders(\DateTime $lastModified, $eTag, $maxAge)
    {
        $this->response->setMaxAge($maxAge);
        $this->response->setPublic();

        if ($this->maxAge === 0) {
            $this->response->headers->set('Cache-Control', 'no-cache');

            return;
        }

        $this->response->setLastModified($lastModified);
        $this->response->setEtag($eTag);
    }
1239331
protected function isFresh($destination, \DateTime $maxAge = null)
    {
        // fetch if file does not exist
        if (!file_exists($destination)) {
            return false;
        }

        // if file exists and no max-age is given, use the cached file
        if (!$maxAge instanceof \DateTime) {
            return true;
        }

        // download if ttl is passed
        $mtime = new \Datetime('@' . filemtime($destination));

        // see if cache has expired
        if ($mtime < $maxAge) {
            return false;
        }

        // check with last modified date (if available)
        if (($lastMod = $this->getLastModifiedDate()) && ($mtime < $lastMod)) {
            return false;
        }

        // all checks passed, use the cached version
        return true;
    }
1081027
protected function tryIncludeAnnotationCache()
    {
        if (!$this->debug) {
            $this->includeAnnotationCache();

            return true;
        }

        $metadata = $this->getClassMetadata();
        $reflectionClass = $metadata->getReflectionClass();
        $filename = $reflectionClass->getFileName();
        if ($filename && is_file($filename)) {
            $mtime = filemtime($filename);
            if (($currentfileMtime = filemtime(__FILE__)) > $mtime) {
                $mtime = $currentfileMtime;
            }
            $mtimeAnnotation = filemtime($this->annotationCacheFilename);
            if ($mtime && $mtimeAnnotation && $mtime <= $mtimeAnnotation) {
                $this->includeAnnotationCache();

                return true;
            }
        }

        return false;
    }
1277741
public function isCacheActual() {

        if ( !isset($this->latestCachingTime) ) {
            return false;
        }

        return
            ( (time() - $this->latestCachingTime)
              > self::ONE_DAY_IN_SECONDS );
    }
461065
public function pexpireat($key, $milisecondsTimestamp)
    {
        $this->init();
        $result = $this->driver->pexpireat($key, $milisecondsTimestamp);
        return (bool)$result;
    }
976375
def check_cache(self, e_tag, match):
        """"""
        if e_tag != match:
            return False
        self.send_response(304)
        self.send_header("ETag", e_tag)
        self.send_header("Cache-Control",
                         "max-age={0}".format(self.server.max_age))
        self.end_headers()
        thread_local.size = 0
        return True
632120
protected void checkCache(final Instant modified, final EntityTag etag) {
        HttpUtils.checkIfMatch(getRequest().getHeaders().getFirst(IF_MATCH), etag);
        HttpUtils.checkIfUnmodifiedSince(getRequest().getHeaders().getFirst(IF_UNMODIFIED_SINCE), modified);
        HttpUtils.checkIfNoneMatch(getRequest().getMethod(), getRequest().getHeaders().getFirst(IF_NONE_MATCH), etag);
        HttpUtils.checkIfModifiedSince(getRequest().getMethod(), getRequest().getHeaders().getFirst(IF_MODIFIED_SINCE),
                modified);
    }
187302
protected function isCached()
    {
        $cacheTime = self::CACHE_TIME * 60;

        if (!is_file($this->pathCache)) {
            return false;
        }

        $cachedTime = filemtime($this->pathCache);
        $cacheAge = $this->time - $cachedTime;

        return $cacheAge < $cacheTime;
    }