Skip to content

Commit 803265d

Browse files
committed
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.
1 parent 65eddf0 commit 803265d

File tree

3 files changed

+123
-18
lines changed

3 files changed

+123
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* BehatMage
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the MIT License, that is bundled with this
8+
* package in the file LICENSE.
9+
* It is also available through the world-wide-web at this URL:
10+
*
11+
* http://opensource.org/licenses/MIT
12+
*
13+
* If you did not receive a copy of the license and are unable to obtain it
14+
* through the world-wide-web, please send an email
15+
* to <[email protected]> so we can send you a copy immediately.
16+
*
17+
* @category MageTest
18+
* @package MagentoExtension
19+
* @subpackage Service\Cache
20+
*
21+
* @copyright Copyright (c) 2012-2013 MageTest team and contributors.
22+
*/
23+
namespace MageTest\MagentoExtension\Service\Cache;
24+
25+
use Mage_Core_Model_App;
26+
27+
/**
28+
* ConfigurationCache
29+
*
30+
* @category MageTest
31+
* @package MagentoExtension
32+
* @subpackage Service\Cache
33+
*
34+
* @author MageTest team (https://github.com/MageTest/BehatMage/contributors)
35+
*/
36+
abstract class BaseCache
37+
{
38+
/**
39+
* List of cache types to clear.
40+
*
41+
* For example:
42+
* - config
43+
* - block_html
44+
* - layout
45+
* - translate
46+
*
47+
* @var array
48+
*/
49+
protected $cacheTypes = array();
50+
51+
/**
52+
* Internal instance of MageApp
53+
*
54+
* @var Mage_Core_Model_App
55+
**/
56+
protected $mageApp;
57+
58+
59+
public function __construct(Mage_Core_Model_App $mageApp)
60+
{
61+
$this->mageApp = $mageApp;
62+
}
63+
64+
public function clear()
65+
{
66+
$this->mageApp->cleanCache($this->getCacheTags());
67+
}
68+
69+
/**
70+
* All listed types must be declared under global/cache/types
71+
*
72+
* @return array
73+
*/
74+
private function getCacheTags()
75+
{
76+
$tags = array();
77+
foreach ($this->cacheTypes as $type) {
78+
$tags = array_merge($tags, $this->mageApp->getCacheInstance()->getTagsByType($type));
79+
}
80+
return $tags;
81+
}
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* BehatMage
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the MIT License, that is bundled with this
8+
* package in the file LICENSE.
9+
* It is also available through the world-wide-web at this URL:
10+
*
11+
* http://opensource.org/licenses/MIT
12+
*
13+
* If you did not receive a copy of the license and are unable to obtain it
14+
* through the world-wide-web, please send an email
15+
* to <[email protected]> so we can send you a copy immediately.
16+
*
17+
* @category MageTest
18+
* @package MagentoExtension
19+
* @subpackage Service\Cache
20+
*
21+
* @copyright Copyright (c) 2012-2013 MageTest team and contributors.
22+
*/
23+
namespace MageTest\MagentoExtension\Service\Cache;
24+
25+
use Mage_Core_Model_App;
26+
27+
/**
28+
* ConfigurationCache
29+
*
30+
* @category MageTest
31+
* @package MagentoExtension
32+
* @subpackage Service\Cache
33+
*
34+
* @author MageTest team (https://github.com/MageTest/BehatMage/contributors)
35+
*/
36+
class ConfigurationCache extends BaseCache
37+
{
38+
protected $cacheTypes = array('block_html');
39+
}

src/MageTest/MagentoExtension/Service/Cache/ConfigurationCache.php

+2-18
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,7 @@
3333
*
3434
* @author MageTest team (https://github.com/MageTest/BehatMage/contributors)
3535
*/
36-
class ConfigurationCache
36+
class ConfigurationCache extends BaseCache
3737
{
38-
/**
39-
* Internal instance of MageApp
40-
*
41-
* @var Mage_Core_Model_App
42-
**/
43-
private $mageApp;
44-
45-
public function __construct(Mage_Core_Model_App $mageApp)
46-
{
47-
$this->mageApp = $mageApp;
48-
}
49-
50-
// FIXME This is brutal but it is late
51-
public function clear()
52-
{
53-
$this->mageApp->getCacheInstance()->flush();
54-
}
38+
protected $cacheTypes = array('config');
5539
}

0 commit comments

Comments
 (0)