Skip to content

Commit

Permalink
Improve the process of clearing the cache.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Vinai committed May 21, 2013
1 parent 65eddf0 commit 803265d
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 18 deletions.
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 <[email protected]> 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;
}
}
39 changes: 39 additions & 0 deletions src/MageTest/MagentoExtension/Service/Cache/BlockHtmlCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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 <[email protected]> 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');
}
20 changes: 2 additions & 18 deletions src/MageTest/MagentoExtension/Service/Cache/ConfigurationCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

0 comments on commit 803265d

Please sign in to comment.