Monday, June 24, 2013

Strange cache behavior in console scripts

We are using CakePHP 2.2.3. We moved the tmp folder from /app/tmp to /tmp (to the same level of /app). So we removed the /app/tmp folder and we added these lines to /app/webroot/index.php:

//We like the TMP folder outside the app folder!
define('TMP',  dirname(dirname(dirname(dirname(__FILE__)))).DS.'tmp'.DS);

Every once in a while we have problems with Console shell scripts.
With CORE_DEBUG > 0 everything works fine but when CORE_DEBUG = 0 we get strange error (Ex: table does not exist when instead it exists in the DB). Again everything works with CORE_DEBUG > 0.

The workaround has been deleting the files in: 
/lib/Cake/Console/Templates/skel/tmp/cache/models/

Some questions:
  1.  Why are not the cache files being updated? What is the cache logic?
  2. In ShellDispatcher.php in function _bootstrap(), There is this:
    if (!is_dir(ROOT . DS . APP_DIR . DS . 'tmp')) {
       define('TMP', CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'Console' . DS . 'Templates' . DS . 'skel' . DS . 'tmp' . DS);
    }
    This is pretty awkward. So :
    1. Why is the cache set in this almost impossible to find folder inside the cake core /lib folder ?
    2. Why the condition is if (!is_dir(ROOT . DS . APP_DIR . DS . 'tmp')) ... instead of if (defined('TMP')) ... ?
      This prevents to define TMP in /app/Console/cake.php and the only way to fix is to mess up with ShellDispatcher.php under /lib that makes updating CakePHP a little more error prone (we need to remember that we change stuff in /lib)

--
Best,
   Chris

--Everything should be made as simple as possible, but not simpler (Albert Einstein)
Read it as: "As simple as possible, as complex as necessary"

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: