首先,在我的运行 PHP 5.3.15 的 Macbook Pro 开发服务器上,使用 PECL 成功安装了 Memcache 和 APC(并被验证为工作)
我刚刚烘焙了一个测试 Cake 2.2.2 应用程序。在Config/core.php
我有以下内容:
/**
* 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());
上述最终 debug() 的输出为:
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()
)
因此core.php
,Cake 似乎希望将 Memcache 用作其缓存引擎。
然而,当我localhost/myapp/pages/home
在浏览器中访问时,CakePHP 的默认、新鲜出炉的欢迎页面向我打招呼,通知我The FileEngine is being used for core caching
如果我在我的应用程序中的其他任何地方(除了core.php
)debug(Cache::settings())
,我会得到以下信息:
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()
)
基本上,CakePHP 似乎恢复为 File 进行缓存,忽略我的配置core.php
以使用 Memcache ......除非我在这里做错了什么??!
Configure::write('debug', 0)
我已经用and试过了Configure::write('debug', 1)
。
我应该提到,通过上述,APC 和 Memcache 扩展都在php.ini
.
任何帮助将不胜感激,在此先感谢。