Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow CMS pages to not be banned in Varnish when products are updated #23

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Block/Adminhtml/Report/Edit.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Block\Adminhtml\Report;
Expand All @@ -19,7 +19,7 @@ public function __construct(
) {
parent::__construct($context, $data);
}

protected function _construct()
{
$this->_objectId = 'general_id';
Expand All @@ -28,7 +28,7 @@ protected function _construct()

parent::_construct();
}

/**
* Retrieve text for header element
*
Expand Down
8 changes: 4 additions & 4 deletions Block/Adminhtml/Report/Edit/Form.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Block\Adminhtml\Report\Edit;

use Magento\Backend\Block\Widget\Form\Generic;

class Form extends Generic
{
/**
Expand All @@ -26,7 +26,7 @@ protected function _prepareForm()
);
$form->setUseContainer(true);
$this->setForm($form);

return parent::_prepareForm();
}
}
2 changes: 1 addition & 1 deletion Block/Adminhtml/Report/Edit/Tab/Credentials.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Block\Adminhtml\Report\Edit\Tab;
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/Report/Edit/Tab/Metrics.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Block\Adminhtml\Report\Edit\Tab;
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/Report/Edit/Tab/Settings.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Block\Adminhtml\Report\Edit\Tab;
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/Report/Edit/Tabs.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Block\Adminhtml\Report\Edit;
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Report/FetchInfo.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Controller\Adminhtml\Report;
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Report/Index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Controller\Adminhtml\Report;
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Report/Save.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Controller\Adminhtml\Report;
Expand Down
2 changes: 1 addition & 1 deletion Controller/Index/Index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Section.io. All rights reserved.
* Copyright © 2018 Section.io. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Controller\Index;
Expand Down
2 changes: 1 addition & 1 deletion Controller/Router.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Section.io. All rights reserved.
* Copyright © 2018 Section.io. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Controller;
Expand Down
2 changes: 1 addition & 1 deletion Helper/Aperture.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Helper;
Expand Down
2 changes: 1 addition & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Helper;
Expand Down
2 changes: 1 addition & 1 deletion Helper/State.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Helper;
Expand Down
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016, section.io
Copyright (c) 2018, section.io
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand All @@ -7,4 +7,4 @@ Redistribution and use in source and binary forms, with or without modification,

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 2 additions & 2 deletions Model/Account.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Model;
Expand All @@ -22,7 +22,7 @@ public function __construct(
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {

parent::__construct($context, $registry, $resource, $resourceCollection, $data);
}

Expand Down
4 changes: 2 additions & 2 deletions Model/Application.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Model;
Expand All @@ -22,7 +22,7 @@ public function __construct(
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {

parent::__construct($context, $registry, $resource, $resourceCollection, $data);
}

Expand Down
24 changes: 24 additions & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Model;

/**
* Class Config
*
*/
class Config extends \Magento\PageCache\Model\Config
{

/**
* Returns include CMS in product purge.
*
* @return bool
*/
public function includeCmsInProductPurge()
{
return $this->_scopeConfig->isSetFlag('system/full_page_cache/sectionio/include_cms_in_product_purge');
}
}
21 changes: 19 additions & 2 deletions Model/PurgeCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class PurgeCache
*/
private $logger;

/**
* Application config object
*
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
private $config;

/** @var \Sectionio\Metrics\Helper\State $helper */
protected $state;

Expand All @@ -27,15 +34,18 @@ class PurgeCache
* Constructor
*
* @param InvalidateLogger $logger
* @param \Sectionio\Metrics\Model\Config $config
* @param \Sectionio\Metrics\Helper\State $state
* @param \Sectionio\Metrics\Helper\Aperture $aperture
*/
public function __construct(
InvalidateLogger $logger,
\Sectionio\Metrics\Model\Config $config,
\Sectionio\Metrics\Helper\State $state,
\Sectionio\Metrics\Helper\Aperture $aperture
) {
$this->logger = $logger;
$this->config = $config;
$this->state = $state;
$this->aperture = $aperture;
}
Expand All @@ -54,21 +64,28 @@ public function sendPurgeRequest($tagsPattern)
$environment_name = $this->state->getEnvironmentName();
$proxy_name = $this->state->getProxyName();

$banExpression = urlencode('obj.http.X-Magento-Tags ~ ' . $tagsPattern);

// If this ban contains product tags & includeCmsInProductPurge is false, exclude any object that also has a CMS Page tag
if (!$this->config->includeCmsInProductPurge() && strpos($tagsPattern, \Magento\Catalog\Model\Product::CACHE_TAG) !== false) {
$banExpression .= urlencode(' && obj.http.X-Magento-Tags !~ (^|,)'.\Magento\Cms\Model\Page::CACHE_TAG.'_[0-9]+');
}

$uri = $this->aperture->generateUrl([
'api' => true,
'accountId' => $account_id,
'applicationId' => $application_id,
'environmentName' => $environment_name,
'proxyName' => $proxy_name,
'uriStem' => '/state?async=true&banExpression=' . urlencode('obj.http.X-Magento-Tags ~ ' . $tagsPattern)
'uriStem' => '/state?async=true&banExpression=' . $banExpression
]);

$info = $this->aperture->executeAuthRequest($uri, 'POST', [], self::BAN_TIMEOUT_SECONDS);
if ($info['http_code'] != 200) {
$this->logger->execute('Error executing purge: ' . $tagsPattern.', Error: ' . $info['body_content']);
return false;
}
$this->logger->execute(compact('server', 'tagsPattern'));
return true;
}
}

4 changes: 2 additions & 2 deletions Model/ResourceModel/Account.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Model\ResourceModel;
Expand All @@ -15,7 +15,7 @@ public function __construct(
\Magento\Framework\Model\ResourceModel\Db\Context $context,
$resourcePrefix = null
) {

$this->transactionManager = $context->getTransactionManager();
$this->_resources = $context->getResources();
$this->objectRelationProcessor = $context->getObjectRelationProcessor();
Expand Down
2 changes: 1 addition & 1 deletion Model/ResourceModel/Account/Collection.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Model\ResourceModel\Account;
Expand Down
4 changes: 2 additions & 2 deletions Model/ResourceModel/Application.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Model\ResourceModel;
Expand All @@ -15,7 +15,7 @@ public function __construct(
\Magento\Framework\Model\ResourceModel\Db\Context $context,
$resourcePrefix = null
) {

$this->transactionManager = $context->getTransactionManager();
$this->_resources = $context->getResources();
$this->objectRelationProcessor = $context->getObjectRelationProcessor();
Expand Down
2 changes: 1 addition & 1 deletion Model/ResourceModel/Application/Collection.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Model\ResourceModel\Application;
Expand Down
2 changes: 1 addition & 1 deletion Model/ResourceModel/Settings.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Model\ResourceModel;
Expand Down
2 changes: 1 addition & 1 deletion Model/ResourceModel/Settings/Collection.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Model\ResourceModel\Settings;
Expand Down
4 changes: 2 additions & 2 deletions Model/Settings.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Model;
Expand All @@ -22,7 +22,7 @@ public function __construct(
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {

parent::__construct($context, $registry, $resource, $resourceCollection, $data);
}

Expand Down
6 changes: 3 additions & 3 deletions Observer/InvalidateVarnishObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class InvalidateVarnishObserver implements ObserverInterface
private $purgeCache;

/**
* @param \Magento\PageCache\Model\Config $config
* @param \Sectionio\Metrics\Model\Config $config
* @param \Sectionio\Metrics\Model\PurgeCache $purgeCache
*/
public function __construct(
\Magento\PageCache\Model\Config $config,
\Sectionio\Metrics\Model\Config $config,
\Sectionio\Metrics\Model\PurgeCache $purgeCache
) {
$this->config = $config;
Expand All @@ -43,7 +43,7 @@ public function __construct(
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
if ($this->config->getType() == \Magento\PageCache\Model\Config::VARNISH && $this->config->isEnabled()) {
if ($this->config->getType() == \Sectionio\Metrics\Model\Config::VARNISH && $this->config->isEnabled()) {
$object = $observer->getEvent()->getObject();
if ($object instanceof \Magento\Framework\DataObject\IdentityInterface) {
$tags = [];
Expand Down
2 changes: 1 addition & 1 deletion Setup/InstallSchema.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2016 Sectionio. All rights reserved.
* Copyright © 2018 Sectionio. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Sectionio\Metrics\Setup;
Expand Down
Loading