【问题标题】:CakePHP Cache Config always reverts to File (from Memcache or APC)CakePHP 缓存配置总是恢复为文件(来自 Memcache 或 APC)
【发布时间】:2012-10-09 18:50:34
【问题描述】:

首先,在我运行 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)Configure::write('debug', 1) 尝试过这个。

我应该提到的是,在上述情况下,php.ini 中启用了 APC 和 Memcache 扩展。

任何帮助将不胜感激,在此先感谢。

【问题讨论】:

    标签: cakephp cakephp-2.0 cakephp-2.1


    【解决方案1】:

    Memcached 应该在某个端口上,默认端口是 11211(检查)...因此您的配置尝试连接到 Memcached,失败并恢复为默认(文件)缓存...

    试试:

    Cache::config('default', array(
        'engine' => 'Memcache',
        'duration'=> 3600, 
        'probability'=> 100, 
        'servers' => array('127.0.0.1:11211') <<<<==
    ));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多