7

I'm using a call to Mage::getSingleton('core/cache')->save() within a controller of mine and it's saving the cached value to the file system (var/cache/) even though Redis is configured as my cache backend, and seemingly all other cache in Magento is being saved properly to Redis.

Here's the save() call:

Mage::getSingleton('core/cache')->save($imageUrl, $cacheKey, array(Mage_Core_Model_Config::CACHE_TAG));

Here's my app/etc/local.xml:

<cache>
    <backend>Cm_Cache_Backend_Redis</backend>
    <backend_options>
        <server>redis11.i</server>
        <port>6379</port>
        <database>2</database>
        <password></password>
        <persistent>cache-db2</persistent>
        <force_standalone>0</force_standalone>
        <connect_retries>1</connect_retries>
        <automatic_cleaning_factor>0</automatic_cleaning_factor>
        <compress_data>1</compress_data>
        <compress_tags>1</compress_tags>
        <compress_threshold>20480</compress_threshold>
        <compression_lib>gzip</compression_lib>
    </backend_options>
</cache>

Why is it saving that cached value to the file system instead of Redis?

5

You should be using Mage::app()->getCache()->save() as the cache gets initialised in the getCache() method by fetching the config and setting this for the cache object, whereas the Mage_Core_Model_Cache constructor does not do this, as far as I can see and it will revert back to the default caching model.

Did a quick test with:

Mage::getSingleton('core/cache')->save(now(), 'time123', array(Mage_Core_Model_Config::CACHE_TAG)); 

AND

Mage::app()->getCache()->save(now(), 'time12345', array(Mage_Core_Model_Config::CACHE_TAG));

Further info:

Mage_Core_Model_App::_initCache actually uses the following to set up the cache object:

$this->_cache = Mage::getModel('core/cache', $options);

Which means the core cache object is not added to the registry for use as a singleton. The first time you call it as a singleton a new core cache object is created and the constructor is called without any options.

  • 1
    Wow, I'm feeling a little bit sheepish right now. That worked! Thanks! – kalenjordan Sep 24 '14 at 21:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.