Skip to content

Commit 8e7a330

Browse files
author
Dale Sikkema
committed
MAGETWO-44681: page cache entries not tagged with "FPC" cache type
- use plugin to add cache tag
1 parent 80c5e2b commit 8e7a330

File tree

3 files changed

+62
-0
lines changed

3 files changed

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

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)