You are here

protected function HttpCache::lookup in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/http-kernel/HttpCache/HttpCache.php \Symfony\Component\HttpKernel\HttpCache\HttpCache::lookup()

Lookups a Response from the cache for the given Request.

When a matching cache entry is found and is fresh, it uses it as the response without forwarding any request to the backend. When a matching cache entry is found but is stale, it attempts to "validate" the entry with the backend using conditional GET. When no matching cache entry is found, it triggers "miss" processing.

Parameters

Request $request A Request instance:

bool $catch whether to process exceptions:

Return value

Response A Response instance

Throws

\Exception

2 calls to HttpCache::lookup()
HttpCache::handle in vendor/symfony/http-kernel/HttpCache/HttpCache.php
Handles a Request to convert it to a Response.
HttpCache::lock in vendor/symfony/http-kernel/HttpCache/HttpCache.php
Locks a Request during the call to the backend.

File

vendor/symfony/http-kernel/HttpCache/HttpCache.php, line 320

Class

HttpCache
Cache provides HTTP caching.

Namespace

Symfony\Component\HttpKernel\HttpCache

Code

protected function lookup(Request $request, $catch = false) {

  // if allow_reload and no-cache Cache-Control, allow a cache reload
  if ($this->options['allow_reload'] && $request
    ->isNoCache()) {
    $this
      ->record($request, 'reload');
    return $this
      ->fetch($request, $catch);
  }
  try {
    $entry = $this->store
      ->lookup($request);
  } catch (\Exception $e) {
    $this
      ->record($request, 'lookup-failed');
    if ($this->options['debug']) {
      throw $e;
    }
    return $this
      ->pass($request, $catch);
  }
  if (null === $entry) {
    $this
      ->record($request, 'miss');
    return $this
      ->fetch($request, $catch);
  }
  if (!$this
    ->isFreshEnough($request, $entry)) {
    $this
      ->record($request, 'stale');
    return $this
      ->validate($request, $entry, $catch);
  }
  $this
    ->record($request, 'fresh');
  $entry->headers
    ->set('Age', $entry
    ->getAge());
  return $entry;
}