-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IBX-1784: Introduced translation-aware HTTP cache invalidation on con…
…tent publication (#166) * Introduced translation-aware HTTP cache invalidation on content publication * Added Behat tests Co-authored-by: Marek Nocoń <[email protected]>
- Loading branch information
1 parent
18e07b7
commit 6b3a1da
Showing
14 changed files
with
301 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@setup @translationAware | ||
Feature: Set system to use translation-aware cache invalidation | ||
|
||
Scenario: Set up the system to use translation-aware cache invalidation | ||
Given I append configuration to "parameters" | ||
""" | ||
ibexa.http_cache.translation_aware.enabled: true | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
@varnish | ||
Feature: As an site administrator I want my pages to be cached using Varnish | ||
|
||
@APIUser:admin | ||
Scenario Outline: Correct translation is displayed when a new translation is published | ||
Given I create "Folder" Content items in root in "pol-PL" | ||
| name | short_name | | ||
| TestFolder | <itemName> | | ||
And I am viewing the pages on siteaccess "site" as "<user>" "<password>" | ||
And I visit "<itemName>" on siteaccess "site" | ||
And I reload the page | ||
And I see correct preview data for "Folder" Content Type | ||
| field | value | | ||
| title | <itemName> | | ||
And response headers contain | ||
| Header | Value | | ||
| X-Cache | HIT | | ||
When I edit "<itemName>" Content item in "eng-GB" | ||
| short_name | | ||
| <itemNameAfterEdit> | | ||
And I reload the page | ||
# Give Varnish time to fetch the backend response | ||
And I wait 5 seconds | ||
# Second reload is needed because of soft purging | ||
And I reload the page | ||
And I reload the page | ||
Then I see correct preview data for "Folder" Content Type | ||
| field | value | | ||
| title | <itemNameAfterEdit> | | ||
And response headers contain | ||
| Header | Value | | ||
| X-Cache | HIT | | ||
|
||
Examples: | ||
| user | password | itemName | itemNameAfterEdit | | ||
| admin | publish | ItemPolskiAdmin | ItemEnglishAdmin | | ||
| anonymous | | ItemPolskiAnon | ItemEnglishAnon | | ||
|
||
@APIUser:admin @javascript @translationNotAware | ||
Scenario: Main translation cache is purged when a fallback translation is edited | ||
Given I am viewing the pages on siteaccess "site" as "admin" with password "publish" | ||
And I create "embeddedContentType" Content items in root in "eng-GB" | ||
| name | | ||
| EmbeddedTranslationEnglish | | ||
And I create "embeddingContentType_no_esi" Content items in root in "eng-GB" | ||
| name | relation | | ||
| EmbeddingTranslationEnglish | /EmbeddedTranslationEnglish | | ||
And I edit "EmbeddedTranslationEnglish" Content item in "fre-FR" | ||
| name | | ||
| EmbeddedTranslationFrench | | ||
And I start measuring time | ||
And I visit "/EmbeddingTranslationEnglish" on siteaccess "site" | ||
And the action took longer than 5 seconds | ||
And I should see "EmbeddingTranslationEnglish" | ||
And I should see "EmbeddedTranslationEnglish" | ||
And I start measuring time | ||
And I reload the page | ||
And the action took no longer than 1 seconds | ||
When I edit "EmbeddedTranslationEnglish" Content item in "fre-FR" | ||
| name | | ||
| EmbeddedTranslationFrenchEdited | | ||
# Give Varnish time to get purged | ||
And I wait 1 seconds | ||
And I start measuring time | ||
And I reload the page | ||
And I reload the page | ||
Then I should see "EmbeddingTranslationEnglish" | ||
And I should see "EmbeddedTranslationEnglish" | ||
And the action took longer than 5 seconds | ||
|
||
@APIUser:admin @javascript @translationAware | ||
Scenario: Main translation cache is not purged when a fallback translation is edited | ||
Given I am viewing the pages on siteaccess "site" as "admin" with password "publish" | ||
And I create "embeddedContentType" Content items in root in "eng-GB" | ||
| name | | ||
| EmbeddedTranslationEnglish | | ||
And I create "embeddingContentType_no_esi" Content items in root in "eng-GB" | ||
| name | relation | | ||
| EmbeddingTranslationEnglish | /EmbeddedTranslationEnglish | | ||
And I edit "EmbeddedTranslationEnglish" Content item in "fre-FR" | ||
| name | | ||
| EmbeddedTranslationFrench | | ||
And I start measuring time | ||
And I visit "/EmbeddingTranslationEnglish" on siteaccess "site" | ||
And the action took longer than 5 seconds | ||
And I should see "EmbeddingTranslationEnglish" | ||
And I should see "EmbeddedTranslationEnglish" | ||
And I start measuring time | ||
And I reload the page | ||
And the action took no longer than 1 seconds | ||
When I edit "EmbeddedTranslationEnglish" Content item in "fre-FR" | ||
| name | | ||
| EmbeddedTranslationFrenchEdited | | ||
# Give Varnish time to get purged | ||
And I wait 1 seconds | ||
And I start measuring time | ||
And I reload the page | ||
And I reload the page | ||
Then I should see "EmbeddingTranslationEnglish" | ||
And I should see "EmbeddedTranslationEnglish" | ||
And the action took no longer than 1 seconds |
57 changes: 57 additions & 0 deletions
57
src/EventSubscriber/AddContentLanguageHeaderSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\HttpCache\EventSubscriber; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Content; | ||
use eZ\Publish\Core\MVC\Symfony\View\CachableView; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\HttpKernel\KernelEvents; | ||
use Symfony\Component\HttpKernel\Event\ResponseEvent; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
|
||
final class AddContentLanguageHeaderSubscriber implements EventSubscriberInterface | ||
{ | ||
public const CONTENT_LANGUAGE_HEADER = 'x-lang'; | ||
|
||
/** @var bool */ | ||
private $isTranslationAware; | ||
|
||
public function __construct(bool $isTranslationAware) | ||
{ | ||
$this->isTranslationAware = $isTranslationAware; | ||
} | ||
|
||
public function onKernelResponse(ResponseEvent $event) | ||
{ | ||
if (!$this->isTranslationAware || HttpKernelInterface::MASTER_REQUEST != $event->getRequestType()) { | ||
return; | ||
} | ||
|
||
$request = $event->getRequest(); | ||
$view = $request->attributes->get('view'); | ||
if (!$view instanceof CachableView || !$view->isCacheEnabled()) { | ||
return; | ||
} | ||
|
||
$content = $request->attributes->get('content'); | ||
if ($content instanceof Content) { | ||
$event->getResponse()->headers->add([self::CONTENT_LANGUAGE_HEADER => $content->getDefaultLanguageCode()]); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
KernelEvents::RESPONSE => 'onKernelResponse', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.