From 803265d2a413a124c28fab7e881c4fa11ec57640 Mon Sep 17 00:00:00 2001 From: Vinai Kopp Date: Tue, 21 May 2013 16:12:17 +0200 Subject: [PATCH 1/2] Improve the process of clearing the cache. Each cache type can consist of one or more cache tags. This patch uses the cache tags that have been configured in magento for each cache segment instead of using a single hardcoded 'config' tag. This touches on issue #19, but doesn't resolve it completely yet. --- .../Service/Cache/BaseCache.php | 82 +++++++++++++++++++ .../Service/Cache/BlockHtmlCache.php | 39 +++++++++ .../Service/Cache/ConfigurationCache.php | 20 +---- 3 files changed, 123 insertions(+), 18 deletions(-) create mode 100644 src/MageTest/MagentoExtension/Service/Cache/BaseCache.php create mode 100644 src/MageTest/MagentoExtension/Service/Cache/BlockHtmlCache.php diff --git a/src/MageTest/MagentoExtension/Service/Cache/BaseCache.php b/src/MageTest/MagentoExtension/Service/Cache/BaseCache.php new file mode 100644 index 0000000..895514b --- /dev/null +++ b/src/MageTest/MagentoExtension/Service/Cache/BaseCache.php @@ -0,0 +1,82 @@ + so we can send you a copy immediately. + * + * @category MageTest + * @package MagentoExtension + * @subpackage Service\Cache + * + * @copyright Copyright (c) 2012-2013 MageTest team and contributors. + */ +namespace MageTest\MagentoExtension\Service\Cache; + +use Mage_Core_Model_App; + +/** + * ConfigurationCache + * + * @category MageTest + * @package MagentoExtension + * @subpackage Service\Cache + * + * @author MageTest team (https://github.com/MageTest/BehatMage/contributors) + */ +abstract class BaseCache +{ + /** + * List of cache types to clear. + * + * For example: + * - config + * - block_html + * - layout + * - translate + * + * @var array + */ + protected $cacheTypes = array(); + + /** + * Internal instance of MageApp + * + * @var Mage_Core_Model_App + **/ + protected $mageApp; + + + public function __construct(Mage_Core_Model_App $mageApp) + { + $this->mageApp = $mageApp; + } + + public function clear() + { + $this->mageApp->cleanCache($this->getCacheTags()); + } + + /** + * All listed types must be declared under global/cache/types + * + * @return array + */ + private function getCacheTags() + { + $tags = array(); + foreach ($this->cacheTypes as $type) { + $tags = array_merge($tags, $this->mageApp->getCacheInstance()->getTagsByType($type)); + } + return $tags; + } +} diff --git a/src/MageTest/MagentoExtension/Service/Cache/BlockHtmlCache.php b/src/MageTest/MagentoExtension/Service/Cache/BlockHtmlCache.php new file mode 100644 index 0000000..d81b665 --- /dev/null +++ b/src/MageTest/MagentoExtension/Service/Cache/BlockHtmlCache.php @@ -0,0 +1,39 @@ + so we can send you a copy immediately. + * + * @category MageTest + * @package MagentoExtension + * @subpackage Service\Cache + * + * @copyright Copyright (c) 2012-2013 MageTest team and contributors. + */ +namespace MageTest\MagentoExtension\Service\Cache; + +use Mage_Core_Model_App; + +/** + * ConfigurationCache + * + * @category MageTest + * @package MagentoExtension + * @subpackage Service\Cache + * + * @author MageTest team (https://github.com/MageTest/BehatMage/contributors) + */ +class ConfigurationCache extends BaseCache +{ + protected $cacheTypes = array('block_html'); +} diff --git a/src/MageTest/MagentoExtension/Service/Cache/ConfigurationCache.php b/src/MageTest/MagentoExtension/Service/Cache/ConfigurationCache.php index 03c9d4c..3b89648 100644 --- a/src/MageTest/MagentoExtension/Service/Cache/ConfigurationCache.php +++ b/src/MageTest/MagentoExtension/Service/Cache/ConfigurationCache.php @@ -33,23 +33,7 @@ * * @author MageTest team (https://github.com/MageTest/BehatMage/contributors) */ -class ConfigurationCache +class ConfigurationCache extends BaseCache { - /** - * Internal instance of MageApp - * - * @var Mage_Core_Model_App - **/ - private $mageApp; - - public function __construct(Mage_Core_Model_App $mageApp) - { - $this->mageApp = $mageApp; - } - - // FIXME This is brutal but it is late - public function clear() - { - $this->mageApp->getCacheInstance()->flush(); - } + protected $cacheTypes = array('config'); } From 617f1231075dd6f6110217244223e0bd4697db24 Mon Sep 17 00:00:00 2001 From: Vinai Kopp Date: Tue, 21 May 2013 17:36:35 +0200 Subject: [PATCH 2/2] Add layout cache service and remove unused namespaces --- .../Service/Cache/BlockHtmlCache.php | 4 +- .../Service/Cache/ConfigurationCache.php | 2 - .../Service/Cache/LayoutCache.php | 37 +++++++++++++++++++ 3 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 src/MageTest/MagentoExtension/Service/Cache/LayoutCache.php diff --git a/src/MageTest/MagentoExtension/Service/Cache/BlockHtmlCache.php b/src/MageTest/MagentoExtension/Service/Cache/BlockHtmlCache.php index d81b665..0d9c162 100644 --- a/src/MageTest/MagentoExtension/Service/Cache/BlockHtmlCache.php +++ b/src/MageTest/MagentoExtension/Service/Cache/BlockHtmlCache.php @@ -22,8 +22,6 @@ */ namespace MageTest\MagentoExtension\Service\Cache; -use Mage_Core_Model_App; - /** * ConfigurationCache * @@ -33,7 +31,7 @@ * * @author MageTest team (https://github.com/MageTest/BehatMage/contributors) */ -class ConfigurationCache extends BaseCache +class BlockHtmlCache extends BaseCache { protected $cacheTypes = array('block_html'); } diff --git a/src/MageTest/MagentoExtension/Service/Cache/ConfigurationCache.php b/src/MageTest/MagentoExtension/Service/Cache/ConfigurationCache.php index 3b89648..8316558 100644 --- a/src/MageTest/MagentoExtension/Service/Cache/ConfigurationCache.php +++ b/src/MageTest/MagentoExtension/Service/Cache/ConfigurationCache.php @@ -22,8 +22,6 @@ */ namespace MageTest\MagentoExtension\Service\Cache; -use Mage_Core_Model_App; - /** * ConfigurationCache * diff --git a/src/MageTest/MagentoExtension/Service/Cache/LayoutCache.php b/src/MageTest/MagentoExtension/Service/Cache/LayoutCache.php new file mode 100644 index 0000000..31ddfe5 --- /dev/null +++ b/src/MageTest/MagentoExtension/Service/Cache/LayoutCache.php @@ -0,0 +1,37 @@ + so we can send you a copy immediately. + * + * @category MageTest + * @package MagentoExtension + * @subpackage Service\Cache + * + * @copyright Copyright (c) 2012-2013 MageTest team and contributors. + */ +namespace MageTest\MagentoExtension\Service\Cache; + +/** + * ConfigurationCache + * + * @category MageTest + * @package MagentoExtension + * @subpackage Service\Cache + * + * @author MageTest team (https://github.com/MageTest/BehatMage/contributors) + */ +class LayoutCache extends BaseCache +{ + protected $cacheTypes = array('layout'); +}