Uploader

An all around general purpose file uploader for CakePHP. Packaged as a stand alone plugin with file validation, file scanning and support for a wide range of basic mime types.

Pitfalls within Cake's Cache engine

Saturday, January 30th 2010, 2:41pm
Topics: Tutorials, CakePHP
Tags: Cache, Error, We Game, Datasource, Engine, Exception
Comments: 2
Permalink - Tinylink

For the past week I have been working on a DataSource for the WeGame API. Everything was working fine until I added some logic to cache the results. No matter what I did I received the following fatal error:

Fatal error: Call to a member function init() on a non-object in C:\xampp\htdocs\cake_1.2.5\cake\libs\cache.php on line 195

// Line 195
$_this->_Engine[$engine]->init($settings);


The error was being thrown from within Cache::set() and it seemed to fail because the actual storage engine object was not instantiated. I spent a good couple hours trying to track down the bug, but to no avail. I tried removing Cache::set(), placing Cache::config() within config/core.php, but still nothing.

Finally I thought to myself "Let me check my Config settings", so I did. I noticed that Cache.disable was set to true, and once I set it to false the whole system worked! Bah, pretty annoying right? I sure love Cake, but its error and exception handling isn't that great. I've ran into so many of these case scenarios where a simple trigger_error() or uncaught exception would of helped (This is for you Cake team *cough*2.0*cough*).

One other thing I would like to note, is that the path option in Cache::config() does not actually create the folder, you must do that manually. Here's how I resolved that problem.

$cachePath = CACHE .'we_game'. DS;
 
// Create the cache dir
if (!file_exists($cachePath)) {
	$this->Folder = new Folder();
	$this->Folder->create($cachePath, 0777);
}
 
Cache::config('weGame', array('path' => $cachePath));
Related Entries:

2 Comments

10 / 2 = ?
Allowed: [code] [b] [i] [u]
  • Graham Weldon
    grahamweldon.com
    Jan 30th 2010, 15:46
    1 I'll do this for you this time, but this could have made a good enhancement ticket over at http://cakephp.lighthouseapp.com, which woule mean your efforts and frustrations could be channelled into helping improve and evolve the framework.
  • Miles Johnson
    milesj.me
    Jan 31st 2010, 00:03
    2 @Graham - Of course. Was planning on it, just had no time so far :P