Symfony\Component\HttpFoundation\Response::isNotModified PHP Method

isNotModified() public method

If the Response is not modified, it sets the status code to 304 and removes the actual content by calling the setNotModified() method.
public isNotModified ( Request $request ) : boolean
$request Request A Request instance
return boolean true if the Response validators match the Request, false otherwise
    public function isNotModified(Request $request)
    {
        if (!$request->isMethodCacheable()) {
            return false;
        }

        $notModified = false;
        $lastModified = $this->headers->get('Last-Modified');
        $modifiedSince = $request->headers->get('If-Modified-Since');

        if ($etags = $request->getETags()) {
            $notModified = in_array($this->getEtag(), $etags) || in_array('*', $etags);
        }

        if ($modifiedSince && $lastModified) {
            $notModified = strtotime($modifiedSince) >= strtotime($lastModified) && (!$etags || $notModified);
        }

        if ($notModified) {
            $this->setNotModified();
        }

        return $notModified;
    }

Usage Example

 public function intercept(MethodInvocation $invocation)
 {
     /*
      * First let's make sure we can even bother caching this
      * if we can't then just return the controller response
      */
     if (!$this->decider->decide()) {
         return $invocation->proceed();
     }
     /* @var $controller ResourceController */
     $controller = $invocation->object;
     /* @var $request Request */
     $request = $invocation->arguments[0];
     // Current Resource
     $resource = $controller->findOr404($request);
     // Cache Options
     $options = $request->attributes->get('_sylius', []);
     $cacheOptions = array_key_exists('cache', $options) ? $options['cache'] : [];
     // Build the actual cache options since we'll need to use it twice
     $this->parser->process($cacheOptions, $resource);
     // Create a preliminary response to see if it is already cached
     $cachedResponse = new Response();
     $cachedResponse->setCache($cacheOptions);
     if ($cachedResponse->isNotModified($request)) {
         return $cachedResponse;
     }
     // If not we take the response back from the controller and modify it again
     $controllerResponse = $invocation->proceed();
     $controllerResponse->setCache($cacheOptions);
     return $controllerResponse;
 }
All Usage Examples Of Symfony\Component\HttpFoundation\Response::isNotModified