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


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

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?


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.

  • Thanks @davidalger. Should have thought to check that. The interesting thing I found was that even though the var/cache directory was 777, the cache files were only 400 (rw for the web user only). – Luke Mills Jul 10 '13 at 0:31
  • If you take a look in Zend_Cache_Backend_File::_filePutContents you'll notice that it calls chmod on cache files when it writes them out. The default permission set is 0700 for directories and 0600 for files. – davidalger Jul 10 '13 at 13:46

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

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.