Skip to content

Commit

Permalink
Merge pull request #11 from technodelight/feature/fix-clearing-contai…
Browse files Browse the repository at this point in the history
…ner-on-cache-flush

Listen to cache:flush events
  • Loading branch information
Jon Acker authored Sep 19, 2016
2 parents 7f5ba91 + 25d6883 commit 9e74e53
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
33 changes: 22 additions & 11 deletions app/code/community/Inviqa/SymfonyContainer/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@ class Inviqa_SymfonyContainer_Model_Observer

public function onCacheRefresh(Varien_Event_Observer $event)
{
if (ConfigurationBuilder::MODEL_ALIAS === $event->getType()) {
$containerFilePath = $this->containerCachePath();
$metaFilePath = $this->containerCacheMetaPath();

if (file_exists($containerFilePath)) {
unlink($containerFilePath);
}

if (file_exists($metaFilePath)) {
unlink($metaFilePath);
}
if ($event->getType() === ConfigurationBuilder::MODEL_ALIAS) {
$this->clearCache();
}
}

public function onCacheFlush()
{
$this->clearCache();
}

public function onPreDispatch(Varien_Event_Observer $event)
{
$controller = $event->getControllerAction();
Expand All @@ -34,6 +31,20 @@ public function onPreDispatch(Varien_Event_Observer $event)
])->setupDependencies($controller);
}

private function clearCache()
{
$containerFilePath = $this->containerCachePath();
$metaFilePath = $this->containerCacheMetaPath();

if (file_exists($containerFilePath)) {
unlink($containerFilePath);
}

if (file_exists($metaFilePath)) {
unlink($metaFilePath);
}
}

private function containerCachePath()
{
return Mage::getBaseDir('cache') . DIRECTORY_SEPARATOR . ConfigurationBuilder::CACHED_CONTAINER;
Expand Down
20 changes: 19 additions & 1 deletion app/code/community/Inviqa/SymfonyContainer/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@
</inviqa_symfonyContainer>
</observers>
</adminhtml_cache_refresh_type>
<adminhtml_cache_flush_all>
<observers>
<inviqa_symfonyContainer>
<class>Inviqa_SymfonyContainer_Model_Observer</class>
<type>singleton</type>
<method>onCacheFlush</method>
</inviqa_symfonyContainer>
</observers>
</adminhtml_cache_flush_all>
<adminhtml_cache_flush_system>
<observers>
<inviqa_symfonyContainer>
<class>Inviqa_SymfonyContainer_Model_Observer</class>
<type>singleton</type>
<method>onCacheFlush</method>
</inviqa_symfonyContainer>
</observers>
</adminhtml_cache_flush_system>
<controller_action_predispatch>
<observers>
<inviqa_symfonyContainer>
Expand All @@ -43,4 +61,4 @@
</cache>
</global>

</config>
</config>

0 comments on commit 9e74e53

Please sign in to comment.