function HttpCache::lock
Locks a Request during the call to the backend.
Return value
bool true if the cache entry can be returned even if it is staled, false otherwise
1 call to HttpCache::lock()
- HttpCache::isFreshEnough in vendor/
symfony/ http-kernel/ HttpCache/ HttpCache.php - Checks whether the cache entry is "fresh enough" to satisfy the Request.
File
-
vendor/
symfony/ http-kernel/ HttpCache/ HttpCache.php, line 542
Class
- HttpCache
- Cache provides HTTP caching.
Namespace
Symfony\Component\HttpKernel\HttpCacheCode
protected function lock(Request $request, Response $entry) : bool {
// try to acquire a lock to call the backend
$lock = $this->store
->lock($request);
if (true === $lock) {
// we have the lock, call the backend
return false;
}
// there is already another process calling the backend
// May we serve a stale response?
if ($this->mayServeStaleWhileRevalidate($entry)) {
$this->record($request, 'stale-while-revalidate');
return true;
}
// wait for the lock to be released
if ($this->waitForLock($request)) {
// replace the current entry with the fresh one
$new = $this->lookup($request);
$entry->headers = $new->headers;
$entry->setContent($new->getContent());
$entry->setStatusCode($new->getStatusCode());
$entry->setProtocolVersion($new->getProtocolVersion());
foreach ($new->headers
->getCookies() as $cookie) {
$entry->headers
->setCookie($cookie);
}
}
else {
// backend is slow as hell, send a 503 response (to avoid the dog pile effect)
$entry->setStatusCode(503);
$entry->setContent('503 Service Unavailable');
$entry->headers
->set('Retry-After', 10);
}
return true;
}