Skip to content

Commit 9542e30

Browse files
author
Joan He
committed
Merge remote-tracking branch 'origin/MAGETWO-44681-fpc-not-refreshed' into develop
2 parents 2b1b5a4 + 40d3e32 commit 9542e30

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/***
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\PageCache\Model\App;
8+
9+
class PageCachePlugin
10+
{
11+
/**
12+
* Attach FPC tag to all saved entries to enable cache type management
13+
*
14+
* @param \Magento\Framework\App\PageCache\Cache $subject
15+
* @param string $data
16+
* @param string $identifier
17+
* @param string[] $tags
18+
* @param int|null $lifeTime
19+
* @return array
20+
*
21+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
22+
*/
23+
public function beforeSave(
24+
\Magento\Framework\App\PageCache\Cache $subject,
25+
$data,
26+
$identifier,
27+
$tags = [],
28+
$lifeTime = null
29+
) {
30+
$tags[] = \Magento\PageCache\Model\Cache\Type::CACHE_TAG;
31+
return [$data, $identifier, $tags, $lifeTime];
32+
}
33+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/***
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\PageCache\Test\Unit\Model\App;
8+
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
use Magento\PageCache\Model\Cache\Type;
11+
12+
class PageCachePluginTest extends \PHPUnit_Framework_TestCase
13+
{
14+
public function testBeforeSave()
15+
{
16+
/** @var \Magento\PageCache\Model\App\PageCachePlugin $plugin */
17+
$plugin = (new ObjectManager($this))->getObject('\Magento\PageCache\Model\App\PageCachePlugin');
18+
$subjectMock = $this->getMockBuilder('\Magento\Framework\App\PageCache\Cache')
19+
->disableOriginalConstructor()
20+
->getMock();
21+
$initTags = ['tag', 'otherTag'];
22+
$result = $plugin->beforeSave($subjectMock, 'data', 'identifier', $initTags);
23+
$tags = isset($result[2]) ? $result[2] : null;
24+
$expectedTags = array_merge($initTags, [Type::CACHE_TAG]);
25+
$this->assertNotNull($tags);
26+
foreach ($expectedTags as $expected) {
27+
$this->assertContains($expected, $tags);
28+
}
29+
}
30+
}

app/code/Magento/PageCache/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@
1010
<plugin name="core-app-area-design-exception-plugin"
1111
type="Magento\PageCache\Model\App\CacheIdentifierPlugin" sortOrder="10"/>
1212
</type>
13+
<type name="Magento\Framework\App\PageCache\Cache">
14+
<plugin name="fpc-tag-addition-plugin" type="Magento\PageCache\Model\App\PageCachePlugin"/>
15+
</type>
1316
</config>

0 commit comments

Comments
 (0)