memcacheを導入し、CakePHPから使用

めんどくさがりなので、全てyumで取得。

yum install memcached
yum install php-pecl-memcache


php.iniに設定追加

extension=memcache.so

Memcached起動

/etc/init.d/memcached start

Apache再起動

/etc/init.d/httpd restart

CakePHPのapp/config/core.phpにあるキャッシュ設定を変更

<?php

/**
 *
 * Cache Engine Configuration
 * Default settings provided below
 *
 * File storage engine.
 *
 *    Cache::config('default', array(
 *    'engine' => 'File' //[required]
 *    'duration'=> 3600, //[optional]
 *    'probability'=> 100, //[optional]
 *     'path' => CACHE, //[optional] use system tmp directory - remember to use absolute path
 *     'prefix' => 'cake_', //[optional]  prefix every cache file with this string
 *     'lock' => false, //[optional]  use file locking
 *     'serialize' => true, [optional]
 *  ));
 *
 *
 * APC (http://pecl.php.net/package/APC)
 *
 *    Cache::config('default', array(
 *    'engine' => 'Apc' //[required]
 *    'duration'=> 3600, //[optional]
 *    'probability'=> 100, //[optional]
 *     'prefix' => Inflector::slug(APP_DIR) . '_', //[optional]  prefix every cache file with this string
 *  ));
 *
 * Xcache (http://xcache.lighttpd.net/)
 *
 *    Cache::config('default', array(
 *    'engine' => 'Xcache' //[required]
 *    'duration'=> 3600, //[optional]
 *    'probability'=> 100, //[optional]
 *     'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string
 *    'user' => 'user', //user from xcache.admin.user settings
 *      'password' => 'password', //plaintext password (xcache.admin.pass)
 *  ));
 *
 *
 * Memcache (http://www.danga.com/memcached/)
 *
 *    Cache::config('default', array(
 *    'engine' => 'Memcache' //[required]
 *    'duration'=> 3600, //[optional]
 *    'probability'=> 100, //[optional]
 *     'prefix' => Inflector::slug(APP_DIR) . '_', //[optional]  prefix every cache file with this string
 *     'servers' => array(
 *       '127.0.0.1:11211' // localhost, default port 11211
 *     ), //[optional]
 *     'compress' => false, // [optional] compress data in Memcache (slower, but uses less memory)
 *  ));
 *
 */
//  Cache::config('default', array('engine' => 'File'));
   Cache::config('default', array(
     'engine'     => 'Memcache', //[required]
     'duration'   => 3600, //[optional]
     'probability'=> 100, //[optional]
     'prefix'     => Inflector::slug(APP_DIR) . '_', //[optional]  prefix every cache file with this string
     'servers'    => array(
        '127.0.0.1:11211' // localhost, default port 11211
     ), //[optional]
     'compress'   => false, // [optional] compress data in Memcache (slower, but uses less memory)
   ));

?>


これにより、以下のような結果が得られた。

導入前 導入後
0.8秒前後 0.8秒前後

CakePHPの実行モード(debug値)は0を設定

あんまりかわらないな〜。どっかの設定がおかしいのかも・・・

プライバシーポリシー お問い合わせ