CakePHP缓存配置始终恢复为文件(从Memcache或APC)
首先,在运行PHP5.3.15的Macbook Pro dev服务器上,使用PECL成功安装了Memcache和APC(并验证其工作正常) 我刚刚烤了一个测试蛋糕2.2.2应用程序。在CakePHP缓存配置始终恢复为文件(从Memcache或APC),cakephp,cakephp-2.0,cakephp-2.1,Cakephp,Cakephp 2.0,Cakephp 2.1,首先,在运行PHP5.3.15的Macbook Pro dev服务器上,使用PECL成功安装了Memcache和APC(并验证其工作正常) 我刚刚烤了一个测试蛋糕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 ava
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());
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()
)
上述最终调试()的输出为:
因此,在core.php
中,Cake似乎希望使用Memcache作为其缓存引擎
但是,当我在浏览器中访问localhost/myapp/pages/home
时,CakePHP的默认、新烘焙的欢迎页面向我打招呼,通知我文件引擎正在用于核心缓存
在我的应用程序中的任何其他地方(除了core.php
),如果我debug(Cache::settings())
,我会得到以下信息:
/**
* 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());
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似乎恢复到文件进行缓存,忽略了我在core.php
中使用Memcache的配置。。。除非我做错了什么
我已经用Configure::write('debug',0)
和Configure::write('debug',1)
尝试过这一点
我应该提到的是,有了上述功能,APC和Memcache扩展都在php.ini
中启用
感谢您的帮助。Memcached应该在某个端口上,默认为11211(检查)。。。因此,您的配置尝试连接到Memcached,失败并恢复为默认(文件)缓存 尝试: 缓存::配置('default',数组( “引擎”=>“内存缓存”, “持续时间”=>3600, “概率”=>100,
'servers'=>array('127.0.0.1:11211')Memcached应该在某个端口上,默认端口是11211(检查)…因此您的配置尝试连接到Memcached,失败并恢复为默认(文件)缓存 尝试: 缓存::配置('default',数组( “引擎”=>“内存缓存”, “持续时间”=>3600, “概率”=>100, “服务器”=>阵列('127.0.0.1:11211')