まず、MemcacheとAPCの両方が、PHP5.3.15を実行しているMacbookPro開発サーバーにPECLを使用して正常にインストールされます(動作していることが確認されます)。
テストCake2.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());
上記のfinaldebug()の出力は次のとおりです。
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はキャッシュのためにファイルに戻るように見え、core.php
Memcacheを使用するための構成を無視します...ここで何か間違ったことをしない限り??!
私はこれをConfigure::write('debug', 0)
とで試しましConfigure::write('debug', 1)
た。
上記では、APCとMemcacheの両方の拡張機能がで有効になっていることに注意してくださいphp.ini
。
よろしくお願いします。