Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Fix usage of symfony cache with shared max age 0 #4385

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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