Skip to content

Commit

Permalink
Fix EZP-20509: cache issues when creating content
Browse files Browse the repository at this point in the history
  • Loading branch information
dpobel committed Mar 25, 2013
1 parent 9d0eb18 commit 06b7d29
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions eZ/Publish/Core/MVC/Symfony/Controller/Content/ViewController.php
Expand Up @@ -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;
}
Expand All @@ -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,
Expand Down

0 comments on commit 06b7d29

Please sign in to comment.