public function Store::invalidate

Invalidates all cache entries that match the request.

Parameters

Request $request A Request instance:

Overrides StoreInterface::invalidate

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpCache/Store.php, line 196

Class

Store
Store implements all the logic for storing cache metadata (Request and Response headers).

Namespace

Symfony\Component\HttpKernel\HttpCache

Code

public function invalidate(Request $request) {
  $modified = false;
  $key = $this
    ->getCacheKey($request);
  $entries = array();
  foreach ($this
    ->getMetadata($key) as $entry) {
    $response = $this
      ->restoreResponse($entry[1]);
    if ($response
      ->isFresh()) {
      $response
        ->expire();
      $modified = true;
      $entries[] = array(
        $entry[0],
        $this
          ->persistResponse($response),
      );
    }
    else {
      $entries[] = $entry;
    }
  }
  if ($modified) {
    if (false === $this
      ->save($key, serialize($entries))) {
      throw new \RuntimeException('Unable to store the metadata.');
    }
  }

  // As per the RFC, invalidate Location and Content-Location URLs if present
  foreach (array(
    'Location',
    'Content-Location',
  ) as $header) {
    if ($uri = $request->headers
      ->get($header)) {
      $subRequest = Request::create($uri, 'get', array(), array(), array(), $request->server
        ->all());
      $this
        ->invalidate($subRequest);
    }
  }
}