Skip to content

Commit ff047a9

Browse files
author
Joan He
committed
MAGETWO-44798: [Varnish4] Page cache is not disabled if Varnish is used
1 parent b2f0ef0 commit ff047a9

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed

app/code/Magento/Backend/Controller/Adminhtml/Cache/MassDisable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ public function executeInternal()
2626
}
2727
$this->_validateTypes($types);
2828
foreach ($types as $code) {
29+
$this->_cacheTypeList->cleanType($code);
2930
if ($this->_cacheState->isEnabled($code)) {
3031
$this->_cacheState->setEnabled($code, false);
3132
$updatedTypes++;
3233
}
33-
$this->_cacheTypeList->cleanType($code);
3434
}
3535
if ($updatedTypes > 0) {
3636
$this->_cacheState->persist();

app/code/Magento/Backend/Controller/Adminhtml/Cache/MassRefresh.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function executeInternal()
2727
$this->_validateTypes($types);
2828
foreach ($types as $type) {
2929
$this->_cacheTypeList->cleanType($type);
30-
$this->_eventManager->dispatch('adminhtml_cache_refresh_type', ['type' => $type]);
3130
$updatedTypes++;
3231
}
3332
if ($updatedTypes > 0) {

app/code/Magento/PageCache/Model/Cache/Type.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,27 @@ class Type extends \Magento\Framework\Cache\Frontend\Decorator\TagScope
1919
*/
2020
const CACHE_TAG = 'FPC';
2121

22+
/**
23+
* @var \Magento\Framework\Event\ManagerInterface
24+
*/
25+
private $eventManager;
26+
2227
/**
2328
* @param \Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool
29+
* @param \Magento\Framework\Event\ManagerInterface $eventManager
2430
*/
25-
public function __construct(\Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool)
26-
{
31+
public function __construct(
32+
\Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool,
33+
\Magento\Framework\Event\ManagerInterface $eventManager
34+
35+
) {
2736
parent::__construct($cacheFrontendPool->get(self::TYPE_IDENTIFIER), self::CACHE_TAG);
37+
$this->eventManager = $eventManager;
38+
}
39+
40+
public function clean($mode = \Zend_Cache::CLEANING_MODE_ALL, array $tags = [])
41+
{
42+
$this->eventManager->dispatch('adminhtml_cache_refresh_type');
43+
return parent::clean($mode, $tags);
2844
}
2945
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\PageCache\Test\Unit\Model\Cache;
7+
8+
class TypeTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/** @var \Magento\PageCache\Model\Cache\Type */
11+
protected $model;
12+
13+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Event\ManagerInterface */
14+
protected $eventManagerMock;
15+
16+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\Cache\Type\FrontendPool */
17+
protected $cacheFrontendPoolMock;
18+
19+
public function setUp()
20+
{
21+
$this->eventManagerMock = $this->getMockBuilder('Magento\Framework\Event\ManagerInterface')
22+
->disableOriginalConstructor()
23+
->getMock();
24+
$this->cacheFrontendPoolMock = $this->getMockBuilder('Magento\Framework\App\Cache\Type\FrontendPool')
25+
->disableOriginalConstructor()
26+
->getMock();
27+
$cacheFrontend = $this->getMockBuilder('Magento\Framework\Cache\FrontendInterface')
28+
->disableOriginalConstructor()
29+
->getMock();
30+
$this->cacheFrontendPoolMock->expects($this->once())
31+
->method('get')
32+
->willReturn($cacheFrontend);
33+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
34+
$this->model = $objectManager->getObject(
35+
'Magento\PageCache\Model\Cache\Type',
36+
[
37+
'eventManager' => $this->eventManagerMock,
38+
'cacheFrontendPool' => $this->cacheFrontendPoolMock,
39+
]
40+
);
41+
}
42+
43+
public function testClean()
44+
{
45+
$this->eventManagerMock->expects($this->once())
46+
->method('dispatch')
47+
->with('adminhtml_cache_refresh_type');
48+
49+
$this->model->clean();
50+
}
51+
}

0 commit comments

Comments
 (0)