Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ResponseCacheStrategy.php

function ResponseCacheStrategy::update

Overrides ResponseCacheStrategyInterface::update

File

vendor/symfony/http-kernel/HttpCache/ResponseCacheStrategy.php, line 113

Class

ResponseCacheStrategy
ResponseCacheStrategy knows how to compute the Response cache HTTP header based on the different response cache headers.

Namespace

Symfony\Component\HttpKernel\HttpCache

Code

public function update(Response $response) : void {
    // if we have no embedded Response, do nothing
    if (0 === $this->embeddedResponses) {
        return;
    }
    // Remove Etag since it cannot be merged from embedded responses.
    $response->setEtag(null);
    $this->add($response);
    $response->headers
        ->set('Age', $this->age);
    if ($this->isNotCacheableResponseEmbedded) {
        $response->setLastModified(null);
        if ($this->flagDirectives['no-store']) {
            $response->headers
                ->set('Cache-Control', 'no-cache, no-store, must-revalidate');
        }
        else {
            $response->headers
                ->set('Cache-Control', 'no-cache, must-revalidate');
        }
        return;
    }
    $response->setLastModified($this->lastModified ?: null);
    $flags = array_filter($this->flagDirectives);
    if (isset($flags['must-revalidate'])) {
        $flags['no-cache'] = true;
    }
    $response->headers
        ->set('Cache-Control', implode(', ', array_keys($flags)));
    $maxAge = null;
    if (is_numeric($this->ageDirectives['max-age'])) {
        $maxAge = $this->ageDirectives['max-age'] + $this->age;
        $response->headers
            ->addCacheControlDirective('max-age', $maxAge);
    }
    if (is_numeric($this->ageDirectives['s-maxage'])) {
        $sMaxage = $this->ageDirectives['s-maxage'] + $this->age;
        if ($maxAge !== $sMaxage) {
            $response->headers
                ->addCacheControlDirective('s-maxage', $sMaxage);
        }
    }
    if ($this->ageDirectives['expires'] && null !== $maxAge) {
        $date = clone $response->getDate();
        $date = $date->modify('+' . $maxAge . ' seconds');
        $response->setExpires($date);
    }
}
RSS feed
Powered by Drupal