Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rewrite the magento core-cache-model (Mage_Core_Model_Cache)

I have to rewrite the core cache model. And this doesn't work. My first attempt to solve the problem was to try the rewrite with another model... In my config.xml I declared the following

<global>         
  <models>          
    <core>
      <rewrite>
        <**layout**>MyCompany_MyModule_Model_Core_Cache</**layout**>
      </rewrite>
    </core>
  </models>
  ....

and in my class I died in the consturctor.

This works perfectly! So my may in rewriting models is the right one.

But If I don't use the layout-node in the xml but using the cache-node instead this does not work.

So my attempt is the following and this is not working:

<global>         
  <models>          
    <core>
      <rewrite>
        <cache>MyCompany_MyModule_Model_Core_Cache</cache>
      </rewrite>
    </core>
  </models>
  ....

My question now: is there a way to rewrite / overload the "cache-core-model"???

like image 366
netsurfer.rs Avatar asked Jan 17 '23 00:01

netsurfer.rs


2 Answers

The cache will be initialized before module configurations (config.xml) are loaded. The cache-Model was instanciated with Mage::getModel, which caches the modelnames in the registry. So all later tries to get the custom cache-model will also fail.

Solution: put this rewrite statement in the etc/local.xml. This is a bit dirty because the local.xml should only hold module independent stuff. But this is better than copying core files to local.

like image 120
akimo Avatar answered Jan 31 '23 01:01

akimo


I had the same question, but my solution is a little bit different to yours ;-)

Magento will load the XML file from /app/etc/*.xml (this files will not be cached) before everything else in magento. So i created my own file here "cache.xml" and the content is

<?xml version="1.0"?>
<config>
    <global>
        <models>          
            <core>
                <rewrite>
                    <cache>MyCompany_MyModule_Model_Core_Cache</cache>
                </rewrite>
            </core>
        </models>
    </global>
</config>

works perfect in 1.6,1.7 and 1.8

like image 25
Gunah Avatar answered Jan 31 '23 01:01

Gunah