Skip to content

Commit

Permalink
Fix usage of symfony cache with shared max age 0
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Feb 4, 2019
1 parent 74d1738 commit 1e7fdd1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@ CHANGELOG for Sulu
==================

* release/1.5
* BUGFIX #4385 [SuluHttpCacheBundle] Fix usage of symfony cache with s-max-age 0
* ENHANCEMENT #4367 [WebsiteBundle] Remove false deprecation of WebsiteController::renderStructure
* BUGFIX #4376 [SecurityBundle] Exclude role permissions in user API to improve performance

Expand Down
8 changes: 6 additions & 2 deletions src/Sulu/Component/HttpCache/Handler/PublicHandler.php
Expand Up @@ -85,9 +85,13 @@ public function updateResponse(Response $response, StructureInterface $structure
// mark the response as either public or private
$response->setPublic();

// set the private and shared max age
// set the private max age
$response->setMaxAge($this->maxAge);
$response->setSharedMaxAge($this->sharedMaxAge);

// set shared max age only when not 0 else symfony cache will not work
if ($this->sharedMaxAge) {
$response->setSharedMaxAge($this->sharedMaxAge);
}

$proxyTtl = $this->usePageTtl ?
$response->getAge() + $cacheLifetime :
Expand Down
Expand Up @@ -88,6 +88,30 @@ public function testUpdateResponse()
);
}

public function testSharedMaxAgeZeroResponse()
{
$this->response->setPublic()->shouldBeCalled();
$this->response->setMaxAge($this->maxAge)->shouldBeCalled();
// setSharedMaxAge should not be called else symfony cache will not work on s-max-age 0
$this->response->setSharedMaxAge(0)->shouldNotBeCalled();
$this->structure->getCacheLifeTime()
->willReturn(['type' => CacheLifetimeResolverInterface::TYPE_SECONDS, 'value' => 10]);
$this->cacheLifetimeResolver->resolve(CacheLifetimeResolverInterface::TYPE_SECONDS, 10)->willReturn(10);
$this->response->getAge()->willReturn(50);

$handler = new PublicHandler(
$this->cacheLifetimeResolver->reveal(),
$this->maxAge,
0,
true
);

$handler->updateResponse(
$this->response->reveal(),
$this->structure->reveal()
);
}

public function testDisableCache()
{
// disable cache
Expand Down

0 comments on commit 1e7fdd1

Please sign in to comment.