original_string: protected function lock(Request $request, Response $entry)
      {
          // 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;
      }
code: protected function lock(Request $request, Response $entry)
      {
          // 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;
      }
code_tokens: protected function lock ( Request $ request , Response $ entry ) { // 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 ; }
docstring: Locks a Request during the call to the backend.
  
  @return bool true if the cache entry can be returned even if it is staled, false otherwise
docstring_tokens: Locks a Request during the call to the backend .