Question

I have a method that calls the following code from a web request.

Mage::app()->getCache()->save('bar', 'foo', array(), 60*5);

I have another method that calls

Mage::app()->getCache()->load('foo');

The method that loads the cached value returns the correct value when called via a web request, but always returns false when I run the code via the CLI.

The reason that I'm trying to run via the CLI is that the code in question is part of a cron task. I'm using n98-magerun sys:cron:run foobar_cron to run the code.

My initial thought was that maybe running from the CLI would initiate a different store view, but I've stepped through the code and haven't found anything like that.

Trying to get the cached value when running via the web through admin works.

I'm using the standard Magento filesystem cache, and don't have any custom cache settings in my local.xml. Running EE 1.12.0.2.

I would expect that when I set a cache key via a web request that I could access the same value when running via the CLI and vice verca. Why isn't this working as expected, and what can I do to fix it?

Was it helpful?

Solution

My bet is on file permissions. Make sure your var/cache/ directory has read/write for both the shell user and the user Apache runs under.

Where it can't read from the normal cache directory, it will fallback silently to the system temp directory, filling it with more than just a few zend/locale cache records.

OTHER TIPS

If your cache backend is APC then CLI and Apache APC are completely different and can not be shared between the two unfortunately.

If your cache backend is filesystem based then you should look at the permissions. If permissions is an issue you could consider running your cron as the Apache user as a work around though that is not ideal, a better option is to look at using ACL - have a look at the setfacl command if that is applicable to your Linux distro

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top