Skip to content

Commit 7c0c28e

Browse files
authored
Merge pull request #110 from Inchoo/bugfix/disable-varnish
Prevent PurgeCache from triggering purge on Varnish when Fastly is used
2 parents a152239 + 802ae5a commit 7c0c28e

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

Diff for: Model/PageCache/PurgeCachePlugin.php

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace Fastly\Cdn\Model\PageCache;
4+
5+
use Fastly\Cdn\Model\Config;
6+
use Magento\CacheInvalidate\Model\PurgeCache;
7+
8+
/**
9+
* Fastly CDN for Magento
10+
*
11+
* NOTICE OF LICENSE
12+
*
13+
* This source file is subject to the Fastly CDN for Magento End User License Agreement
14+
* that is bundled with this package in the file LICENSE_FASTLY_CDN.txt.
15+
*
16+
* DISCLAIMER
17+
*
18+
* Do not edit or add to this file if you wish to upgrade Fastly CDN to newer
19+
* versions in the future. If you wish to customize this module for your
20+
* needs please refer to http://www.magento.com for more information.
21+
*
22+
* @category Fastly
23+
* @package Fastly_Cdn
24+
* @copyright Copyright (c) 2016 Fastly, Inc. (http://www.fastly.com)
25+
* @license BSD, see LICENSE_FASTLY_CDN.txt
26+
*/
27+
class PurgeCachePlugin
28+
{
29+
/**
30+
* @var Config
31+
*/
32+
protected $config;
33+
34+
/**
35+
* PurgeCachePlugin constructor.
36+
*
37+
* @param Config $config
38+
*/
39+
public function __construct(
40+
Config $config
41+
) {
42+
$this->config = $config;
43+
}
44+
45+
/**
46+
* Prevent Magento from executing purge requests on Varnish when Fastly is enabled
47+
*
48+
* @param PurgeCache $subject
49+
* @param callable $proceed
50+
* @param array ...$args
51+
*/
52+
public function aroundSendPurgeRequest(PurgeCache $subject, callable $proceed, ...$args)
53+
{
54+
if ($this->config->isFastlyEnabled() !== true) {
55+
$proceed(...$args);
56+
}
57+
}
58+
}

Diff for: etc/di.xml

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
<type name="Magento\PageCache\Model\Config">
2828
<plugin name="fastly_emulate_varnish_cache_type" type="Fastly\Cdn\Model\PageCache\ConfigPlugin"/>
2929
</type>
30+
<type name="Magento\CacheInvalidate\Model\PurgeCache">
31+
<plugin name="fastly_disable_varnish_calls" type="Fastly\Cdn\Model\PageCache\PurgeCachePlugin" />
32+
</type>
3033
<type name="Magento\Framework\Console\CommandList">
3134
<arguments>
3235
<argument name="commands" xsi:type="array">

0 commit comments

Comments
 (0)