Firstly both Memcache and APC are installed successfully using PECL (and are verified as working) on my Macbook Pro dev server running PHP 5.3.15
I've just baked a test Cake 2.2.2 app. In Config/core.php
I have the following:
/**
* Pick the caching engine to use. If APC is enabled use it.
* If running via cli - apc is disabled by default. ensure it's available and enabled in this case
*
*/
$engine = 'File';
if (extension_loaded('apc') && function_exists('apc_dec') && (php_sapi_name() !== 'cli' || ini_get('apc.enable_cli'))) {
$engine = 'Apc';
}
if (extension_loaded('memcache') && php_sapi_name() !== 'cli') {
$engine = 'Memcache';
}
// In development mode, caches should expire quickly.
$duration = '+999 days';
if (Configure::read('debug') >= 1) {
$duration = '+10 seconds';
}
// Prefix each application on the same server with a different string, to avoid Memcache and APC conflicts.
$prefix = 'mcmyapp_';
/**
* Configure the cache used for general framework caching. Path information,
* object listings, and translation cache files are stored with this configuration.
*/
Cache::config('_cake_core_', array(
'engine' => $engine,
'prefix' => $prefix . 'cake_core_',
'path' => CACHE . 'persistent' . DS,
'serialize' => ($engine === 'File'),
'duration' => $duration
));
/**
* Configure the cache for model and datasource caches. This cache configuration
* is used to store schema descriptions, and table listings in connections.
*/
Cache::config('_cake_model_', array(
'engine' => $engine,
'prefix' => $prefix . 'cake_model_',
'path' => CACHE . 'models' . DS,
'serialize' => ($engine === 'File'),
'duration' => $duration
));
Cache::config('default', array(
'engine' => $engine,
'serialize' => ($engine === 'File'),
'duration'=>$duration,
'prefix'=>$prefix,
));
debug(Cache::settings());
The output of the above final debug() is:
array(
'prefix' => '*****',
'engine' => 'Memcache',
'serialize' => false,
'duration' => (int) 10,
'servers' => array(
(int) 0 => '127.0.0.1'
),
'compress' => false,
'persistent' => true,
'probability' => (int) 100,
'groups' => array()
)
So in core.php
it appears that Cake wants to use Memcache for its caching engine.
However, when I visit localhost/myapp/pages/home
in my browser, CakePHP's default, freshly-baked welcome page greets me, informing me that The FileEngine is being used for core caching
Anywhere else in my app (other than in core.php
) if I debug(Cache::settings())
, I get the following:
array(
'prefix' => '*****',
'engine' => 'File',
'serialize' => false,
'duration' => (int) 10,
'servers' => array(
(int) 0 => '127.0.0.1'
),
'compress' => false,
'persistent' => true,
'probability' => (int) 100,
'groups' => array()
)
Basically, CakePHP appears to revert to File for caching, ignoring my configuration in core.php
to use Memcache... unless I've done something wrong here??!
I've tried this with Configure::write('debug', 0)
and Configure::write('debug', 1)
.
I should mention that with the above, both APC and Memcache extensions are enabled in php.ini
.
Any help would be gratefully received, thanks in advance.