Skip to content

Commit 9e74e53

Browse files
author
Jon Acker
authored
Merge pull request #11 from technodelight/feature/fix-clearing-container-on-cache-flush
Listen to cache:flush events
2 parents 7f5ba91 + 25d6883 commit 9e74e53

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

app/code/community/Inviqa/SymfonyContainer/Model/Observer.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@ class Inviqa_SymfonyContainer_Model_Observer
1212

1313
public function onCacheRefresh(Varien_Event_Observer $event)
1414
{
15-
if (ConfigurationBuilder::MODEL_ALIAS === $event->getType()) {
16-
$containerFilePath = $this->containerCachePath();
17-
$metaFilePath = $this->containerCacheMetaPath();
18-
19-
if (file_exists($containerFilePath)) {
20-
unlink($containerFilePath);
21-
}
22-
23-
if (file_exists($metaFilePath)) {
24-
unlink($metaFilePath);
25-
}
15+
if ($event->getType() === ConfigurationBuilder::MODEL_ALIAS) {
16+
$this->clearCache();
2617
}
2718
}
19+
20+
public function onCacheFlush()
21+
{
22+
$this->clearCache();
23+
}
24+
2825
public function onPreDispatch(Varien_Event_Observer $event)
2926
{
3027
$controller = $event->getControllerAction();
@@ -34,6 +31,20 @@ public function onPreDispatch(Varien_Event_Observer $event)
3431
])->setupDependencies($controller);
3532
}
3633

34+
private function clearCache()
35+
{
36+
$containerFilePath = $this->containerCachePath();
37+
$metaFilePath = $this->containerCacheMetaPath();
38+
39+
if (file_exists($containerFilePath)) {
40+
unlink($containerFilePath);
41+
}
42+
43+
if (file_exists($metaFilePath)) {
44+
unlink($metaFilePath);
45+
}
46+
}
47+
3748
private function containerCachePath()
3849
{
3950
return Mage::getBaseDir('cache') . DIRECTORY_SEPARATOR . ConfigurationBuilder::CACHED_CONTAINER;

app/code/community/Inviqa/SymfonyContainer/etc/config.xml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@
2222
</inviqa_symfonyContainer>
2323
</observers>
2424
</adminhtml_cache_refresh_type>
25+
<adminhtml_cache_flush_all>
26+
<observers>
27+
<inviqa_symfonyContainer>
28+
<class>Inviqa_SymfonyContainer_Model_Observer</class>
29+
<type>singleton</type>
30+
<method>onCacheFlush</method>
31+
</inviqa_symfonyContainer>
32+
</observers>
33+
</adminhtml_cache_flush_all>
34+
<adminhtml_cache_flush_system>
35+
<observers>
36+
<inviqa_symfonyContainer>
37+
<class>Inviqa_SymfonyContainer_Model_Observer</class>
38+
<type>singleton</type>
39+
<method>onCacheFlush</method>
40+
</inviqa_symfonyContainer>
41+
</observers>
42+
</adminhtml_cache_flush_system>
2543
<controller_action_predispatch>
2644
<observers>
2745
<inviqa_symfonyContainer>
@@ -43,4 +61,4 @@
4361
</cache>
4462
</global>
4563

46-
</config>
64+
</config>

0 commit comments

Comments
 (0)