Check `HTTP_IF_MODIFIED_SINCE` and `HTTP_IF_NONE_MATCH` from server
If true you can send `304 Not Modified`

@param string $modified
@param string $etag
@return bool
430130
public static function match($modified, $etag = null)
    {
        $modifiedsince = Request::header('If-Modified-Since');

        if ($modifiedsince &&
            preg_match('#^[a-z]{3}[,] \d{2} [a-z]{3} \d{4} \d{2}[:]\d{2}[:]\d{2} GMT$#i', $modifiedsince) !== 0 &&
            strtotime($modifiedsince) == $modified) {
            return true;
        }

        $nonematch = Request::header('If-None-Match');

        return $nonematch && trim($nonematch) === $etag;
    }
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;
        }
    }
48529
def if_match(self):
        """"""
        match = True
        if_match = self.request.META.get('HTTP_IF_MATCH')
        if if_match:
            etag = self.etag()
            if etag != if_match:
                match = False
        return match
286283
public static function exists($sSlug): bool
    {
        $aModules = static::modules();

        foreach ($aModules as $oModule) {
            if ($sSlug === $oModule->slug) {
                return true;
            }
        }

        return false;
    }
784693
function checkIfMatch(req, res, next) {
    var clientETags;
    var cur;
    var etag = res.etag || res.getHeader('etag') || '';
    var ifMatch;
    var matched = false;

    if ((ifMatch = req.headers['if-match'])) {

        clientETags = ifMatch.split(/\s*,\s*/);

        for (var i = 0; i < clientETags.length; i++) {
            cur = clientETags[i];

            // only strong comparison

            cur = cur.replace(/^W\//, '');
            cur = cur.replace(/^"(\w*)"$/, '$1');

            if (cur === '*' || cur === etag) {
                matched = true;
                break;
            }
        }

        if (!matched) {
            var err = new PreconditionFailedError(IF_MATCH_FAIL,
                ifMatch,
                etag);
            return (next(err));
        }
    }

    return (next());
}
406782
public function lastModified()
    {
        return $this->lastMod == 0?$this->lastMod = $this->getVariables()->getValue("last_modified"):$this->lastMod;
    }
520602
public function notModified()
    {
        $this->_createStream();
        $this->_setStatus(304);

        $remove = [
            'Allow',
            'Content-Encoding',
            'Content-Language',
            'Content-Length',
            'Content-MD5',
            'Content-Type',
            'Last-Modified'
        ];
        foreach ($remove as $header) {
            $this->_clearHeader($header);
        }
    }
111619
public function withEtag($hash, $weak = false)
    {
        return $this->withHeader('Etag', sprintf('%s"%s"', ($weak) ? 'W/' : null, $hash));
    }
457133
def if_modified_since(self) -> Optional[datetime.datetime]:
        
        return self._http_date(self.headers.get(hdrs.IF_MODIFIED_SINCE))
1189149
private boolean isFresh(final YokeRequest request) {
        // defaults
        boolean etagMatches = true;
        boolean notModified = true;

        // fields
        String modifiedSince = request.getHeader("if-modified-since");
        String noneMatch = request.getHeader("if-none-match");
        String[] noneMatchTokens = null;
        String lastModified = request.response().getHeader("last-modified");
        String etag = request.response().getHeader("etag");

        // unconditional request
        if (modifiedSince == null && noneMatch == null) {
            return false;
        }

        // parse if-none-match
        if (noneMatch != null) {
            noneMatchTokens = noneMatch.split(" *, *");
        }

        // if-none-match
        if (noneMatchTokens != null) {
            etagMatches = false;
            for (String s : noneMatchTokens) {
                if (etag.equals(s) || "*".equals(noneMatchTokens[0])) {
                    etagMatches = true;
                    break;
                }
            }
        }

        // if-modified-since
        if (modifiedSince != null) {
            try {
                Date modifiedSinceDate = parse(modifiedSince);
                Date lastModifiedDate = parse(lastModified);
                notModified = lastModifiedDate.getTime() <= modifiedSinceDate.getTime();
            } catch (ParseException e) {
                notModified = false;
            }
        }

        return etagMatches && notModified;
    }
1296262
public static void writeIfModified(HttpAcceptSession httpSession, File requestFile) throws IOException {
        if (requestFile.isFile() && requestFile.exists()) {
            String etag = getETagHeaderValue(requestFile);
            String ifNoneMatch = httpSession.getReadHeader("If-None-Match");
            String ifModifiedSince = httpSession.getReadHeader("If-Modified-Since");
            if (!hasBeenModified(requestFile, etag, ifNoneMatch, ifModifiedSince)) {
                httpSession.setWriteHeader("ETag", etag);
                httpSession.setStatus(REDIRECT_NOT_MODIFIED);
            }
            else {
                FileInputStream in = new FileInputStream(requestFile);

                byte[] buf = new byte[8192];
                IoBufferAllocatorEx<?> allocator = httpSession.getBufferAllocator();
                IoBufferEx out = allocator.wrap(allocator.allocate(in.available())).setAutoExpander(allocator);
                int length;
                while ((length = in.read(buf)) > 0) {
                    out.put(buf, 0, length);
                }
                out.flip();
                in.close();
                httpSession.setWriteHeader("ETag", etag);
                httpSession.setWriteHeader("Last-Modified", RFC822_FORMAT_PATTERN.format(requestFile.lastModified()));
                httpSession.setWriteHeader("Expires", RFC822_FORMAT_PATTERN.format(System.currentTimeMillis()));
                httpSession.suspendWrite();
                httpSession.write(out);
                httpSession.shutdownWrite();
                httpSession.resumeWrite();

                // Note: callers are responsible for adding the Content-Type header,
                // per KG-866.  See HttpCrossSiteBridgeFilter for an example.
            }
        }
        else {
            httpSession.setStatus(CLIENT_NOT_FOUND);
        }
    }
1259245
public function patch($path, $parameters = null, $version = null, $etag = null)
        {
            return $this->api('PATCH', $path, $parameters, $version, $etag);
        }
373315
@Override
	public void prepareConditionalGet(final HttpUriRequest newRequest) {
		transferFirstHeader("ETag", "If-None-Match", this.response, newRequest);
		transferFirstHeader("Last-Modified", "If-Modified-Since", this.response, newRequest);
	}
1067170
public function check()
    {
        // Using a validation result to capture messages
        $this->result = new ValidationResult();

        $response = $this->client->get($this->getURL());
        $fullURL = $this->getURL();
        if ($response === null) {
            return [
                EnvironmentCheck::ERROR,
                "Cache headers check request failed for $fullURL",
            ];
        }

        //Check that Etag exists
        $this->checkEtag($response);

        // Check Cache-Control settings
        $this->checkCacheControl($response);

        if ($this->result->isValid()) {
            return [
                EnvironmentCheck::OK,
                $this->getMessage(),
            ];
        } else {
            // @todo Ability to return a warning
            return [
                EnvironmentCheck::ERROR,
                $this->getMessage(),
            ];
        }
    }
17840
public function modified($options = [])
    {
        $options += ['embed' => false];

        if ($this->_modified) {
          return true;
        }

        foreach ($this->_data as $index => $entity) {
            if (is_object($entity) && method_exists($entity, 'modified') && $entity->modified($options)) {
                return true;
            }
        }
        return false;
    }
392048
def _UpdateEtag(self, response):
    
    etag = response.headers.get('etag', self.etag)
    etag_updated = self.etag != etag
    self.etag = etag
    return etag_updated
1299667
public static function isResponseCacheable(Google_Http_Request $resp)
  {
    // First, check if the HTTP request was cacheable before inspecting the
    // HTTP response.
    if (false == self::isRequestCacheable($resp)) {
      return false;
    }

    $code = $resp->getResponseHttpCode();
    if (! in_array($code, self::$CACHEABLE_STATUS_CODES)) {
      return false;
    }

    // The resource is uncacheable if the resource is already expired and
    // the resource doesn't have an ETag for revalidation.
    $etag = $resp->getResponseHeader("etag");
    if (self::isExpired($resp) && $etag == false) {
      return false;
    }

    // [rfc2616-14.9.2]  If [no-store is] sent in a response, a cache MUST NOT
    // store any part of either this response or the request that elicited it.
    $cacheControl = $resp->getParsedCacheControl();
    if (isset($cacheControl['no-store'])) {
      return false;
    }

    // Pragma: no-cache is an http request directive, but is occasionally
    // used as a response header incorrectly.
    $pragma = $resp->getResponseHeader('pragma');
    if ($pragma == 'no-cache' || strpos($pragma, 'no-cache') !== false) {
      return false;
    }

    // [rfc2616-14.44] Vary: * is extremely difficult to cache. "It implies that
    // a cache cannot determine from the request headers of a subsequent request
    // whether this response is the appropriate representation."
    // Given this, we deem responses with the Vary header as uncacheable.
    $vary = $resp->getResponseHeader('vary');
    if ($vary) {
      return false;
    }

    return true;
  }