From 06b7d29c24c834a2559915e7fe40704f10c9a9b7 Mon Sep 17 00:00:00 2001 From: Damien Pobel Date: Wed, 20 Mar 2013 14:45:50 +0100 Subject: [PATCH] Fix EZP-20509: cache issues when creating content --- .../Controller/Content/ViewController.php | 43 +++++++------------ 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/eZ/Publish/Core/MVC/Symfony/Controller/Content/ViewController.php b/eZ/Publish/Core/MVC/Symfony/Controller/Content/ViewController.php index 2d4cce696b6..fd32c17c977 100644 --- a/eZ/Publish/Core/MVC/Symfony/Controller/Content/ViewController.php +++ b/eZ/Publish/Core/MVC/Symfony/Controller/Content/ViewController.php @@ -33,34 +33,34 @@ public function __construct( ViewManager $viewManager ) /** * Build the response so that depending on settings it's cacheable * - * @param string $etag - * @param \DateTime $lastModified + * @param string|null $etag + * @param \DateTime|null $lastModified * * @return \Symfony\Component\HttpFoundation\Response */ - protected function buildResponse( $etag, DateTime $lastModified ) + protected function buildResponse( $etag = null, DateTime $lastModified = null ) { $request = $this->getRequest(); $response = new Response(); if ( $this->getParameter( 'content.view_cache' ) === true ) { $response->setPublic(); - $response->setEtag( $etag ); - - // If-None-Match is the request counterpart of Etag response header - // Making the response to vary against it ensures that an HTTP - // reverse proxy caches the different possible variations of the - // response as it can depend on user role for instance. - if ( $request->headers->has( 'If-None-Match' ) - && $this->getParameter( 'content.ttl_cache' ) === true ) + if ( $etag !== null ) + { + $response->setEtag( $etag ); + } + + if ( $this->getParameter( 'content.ttl_cache' ) === true ) { - $response->setVary( 'If-None-Match' ); $response->setSharedMaxAge( $this->getParameter( 'content.default_ttl' ) ); } - $response->setLastModified( $lastModified ); + if ( $lastModified != null ) + { + $response->setLastModified( $lastModified ); + } } return $response; } @@ -86,23 +86,10 @@ public function viewLocation( $locationId, $viewType, $layout = false, array $pa try { - // Assume that location is cached by the repository - $location = $this->getRepository()->getLocationService()->loadLocation( $locationId ); - $contentInfo = $location->getContentInfo(); + $response = $this->buildResponse(); - // @todo: Use a dedicated etag generator, generating a hash - // instead of plain text - $response = $this->buildResponse( - "ezpublish-location-$locationId-$contentInfo->currentVersionNo-$viewType-$layout", - $contentInfo->modificationDate - ); + $location = $this->getRepository()->getLocationService()->loadLocation( $locationId ); $response->headers->set( 'X-Location-Id', $locationId ); - - if ( $response->isNotModified( $this->getRequest() ) ) - { - return $response; - } - $response->setContent( $this->viewManager->renderLocation( $location,