Skip to content

Commit b335a80

Browse files
author
Alistair Stead
committed
Merge pull request #23 from Vinai/improve-cache-service
Improve the process of clearing the cache.
2 parents 2c0677c + 617f123 commit b335a80

File tree

4 files changed

+158
-20
lines changed

4 files changed

+158
-20
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 <magetest@sessiondigital.com> 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,37 @@
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 <magetest@sessiondigital.com> 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+
/**
26+
* ConfigurationCache
27+
*
28+
* @category MageTest
29+
* @package MagentoExtension
30+
* @subpackage Service\Cache
31+
*
32+
* @author MageTest team (https://github.com/MageTest/BehatMage/contributors)
33+
*/
34+
class BlockHtmlCache extends BaseCache
35+
{
36+
protected $cacheTypes = array('block_html');
37+
}

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

+2-20
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
*/
2323
namespace MageTest\MagentoExtension\Service\Cache;
2424

25-
use Mage_Core_Model_App;
26-
2725
/**
2826
* ConfigurationCache
2927
*
@@ -33,23 +31,7 @@
3331
*
3432
* @author MageTest team (https://github.com/MageTest/BehatMage/contributors)
3533
*/
36-
class ConfigurationCache
34+
class ConfigurationCache extends BaseCache
3735
{
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-
}
36+
protected $cacheTypes = array('config');
5537
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 <magetest@sessiondigital.com> 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+
/**
26+
* ConfigurationCache
27+
*
28+
* @category MageTest
29+
* @package MagentoExtension
30+
* @subpackage Service\Cache
31+
*
32+
* @author MageTest team (https://github.com/MageTest/BehatMage/contributors)
33+
*/
34+
class LayoutCache extends BaseCache
35+
{
36+
protected $cacheTypes = array('layout');
37+
}

0 commit comments

Comments
 (0)