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

Improve the process of clearing the cache. #23

Merged
merged 2 commits into from
Jun 3, 2013
Merged
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
82 changes: 82 additions & 0 deletions src/MageTest/MagentoExtension/Service/Cache/BaseCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* BehatMage
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License, that is bundled with this
* package in the file LICENSE.
* It is also available through the world-wide-web at this URL:
*
* http://opensource.org/licenses/MIT
*
* If you did not receive a copy of the license and are unable to obtain it
* through the world-wide-web, please send an email
* to <magetest@sessiondigital.com> 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;
}
}
37 changes: 37 additions & 0 deletions src/MageTest/MagentoExtension/Service/Cache/BlockHtmlCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* BehatMage
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License, that is bundled with this
* package in the file LICENSE.
* It is also available through the world-wide-web at this URL:
*
* http://opensource.org/licenses/MIT
*
* If you did not receive a copy of the license and are unable to obtain it
* through the world-wide-web, please send an email
* to <magetest@sessiondigital.com> 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 BlockHtmlCache extends BaseCache
{
protected $cacheTypes = array('block_html');
}
22 changes: 2 additions & 20 deletions src/MageTest/MagentoExtension/Service/Cache/ConfigurationCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
*/
namespace MageTest\MagentoExtension\Service\Cache;

use Mage_Core_Model_App;

/**
* ConfigurationCache
*
Expand All @@ -33,23 +31,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');
}
37 changes: 37 additions & 0 deletions src/MageTest/MagentoExtension/Service/Cache/LayoutCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* BehatMage
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License, that is bundled with this
* package in the file LICENSE.
* It is also available through the world-wide-web at this URL:
*
* http://opensource.org/licenses/MIT
*
* If you did not receive a copy of the license and are unable to obtain it
* through the world-wide-web, please send an email
* to <magetest@sessiondigital.com> 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');
}