MAMPã§éçºä¸ã®CakePHPãã¼ã¹ã®ã¢ããªãã©ããã§ãã£ãã·ã¥ããã¦ãï¼
MAMPä¸ã§éçºãã¦ãCakePHPãã¼ã¹ã®ã¢ããªã§ããªãã¼ãããã¨èªã¿è¾¼ã¿ãæ©ããªãå ´åãããã¾ãããCakePHPã®ãã£ãã·ã¥ã®ä»çµã¿ãã¡ããã¨ææ¡ãã¦ãªãã£ãã®ã§ãããã©ã«ãã§ä½ãåãã¦ãã®ãã¨ãããããã¯MySQLå´ã®æ¹ãã¨ã¡ãã£ã¨èª¿ã¹ã¦ã¿ã¾ãããç¹ã«æè¿ããã¼ã¿ãã¼ã¹ã«å ¥ããããã¼ãã¼ã¿ãå¢ãã¦ããã®ã§ããªãã¼ãå¾ã®åä½ãéãäºã«æ°ãã¤ãã¾ãããå®éã«ãCakePHPã® echo $this->element('sql_dump'); ã§åºåããããåã¯ã¨ãªã¼ã®æè¦æé*1ãããªãéã£ã¦ããã®ã§ãã©ããããã¼ã¿ãã¼ã¹å¨ãã¨ããè¦å½ã§èª¿ã¹ã¦ãã¾ãã
ä»ã®ã¨ããã®çµè«
MySQLå´
MAMPã®MySQLã¯åæè¨å®ã§ã¯my.confãåå¨ããªãã
ãã㦠have_query_cache=YES ã ãã©ãquery_cache_size=0 ãªã®ã§ãã¯ã¨ãªã¼ãã£ãã·ã¥ã¯ä½¿ããã¦ããªãã
CakePHPå´
CakePHPã§ã¯ã¢ãã«ãã¯ã¨ãªã¼ã¯ãã£ãã·ã¥ããã¦ããªãã
Model->cacheQueries ããããã£ã true ã ã¨ãåãã¯ã¨ãªã¼ã¯ãã£ãã·ã¥ãããããããã¯1ãªã¯ã¨ã¹ã*2ä¸ã«åãã¯ã¨ãªã¼ãçºè¡ãããå ´åã«æå¹ãªãã¡ã¢ãªã«ãã£ãã·ã¥ããããã®ããããåæå¤ã¯ false ã§ãã
Cacheã¯ã©ã¹ã¯ä½¿ããªãèªåã§æ示çã«èªã¿æ¸ãããã¦ä½¿ããã®ã ãããã® Cacheã¯ã©ã¹ã使ã£ããã¥ã¼ãã£ãã·ã¥ã¯ã³ã³ããã¼ã©ã¼ã§ä½¿ãäºãæ示ããå¿
è¦ãããã
http://api13.cakephp.org/class/model
http://api13.cakephp.org/class/cache
ãªã®ã§ã©ãã§ãã£ãã·ã¥ããã¦ãã®ãããããã¯ãã£ãã·ã¥ä»¥å¤ã®ä½ãã§åä½ãéããªã£ã¦ãã®ããã¾ã è¬ãªç¶æ
ã§ããåç´ã«MySQLã®ãã¼ã¿ããæåã®ã¯ã¨ãªã¼ã§ã¡ã¢ãªã«ä¹ã£ãã£ã¦æ©ããªã£ã¦ãã¨ããªã®ããªãï¼
ã¤ãã§ã«ãMySQLã®ã¯ã¨ãªã¼ãã£ãã·ã¥ãæå¹ã«ãã¦ã¿ãããä½æ
ã使ãããªãæ§åãçãã¯åºãªãã£ããã©ãã¨ããããããã¾ã§ã
詳細
MAMP MySQL ã® my.conf
/Applications/MAMP/db/mysql/
MAMPã®my.confã¯ãã®å ´æã«è¨ç½®ãããã®ã§ãããMAMPã®åæç¶æ ã§ã¯åå¨ããªãããã§ããmy.conf ç¡ãã§ãMySQLã£ã¦åããã§ãããç¥ãã¾ããã§ããã
$ ls /Applications/MAMP/Library/share/mysql/my-* /Applications/MAMP/Library/share/mysql/my-huge.cnf /Applications/MAMP/Library/share/mysql/my-innodb-heavy-4G.cnf /Applications/MAMP/Library/share/mysql/my-large.cnf /Applications/MAMP/Library/share/mysql/my-medium.cnf /Applications/MAMP/Library/share/mysql/my-small.cnf
ã¡ãªã¿ã«ãããã« my.conf ã®ãµã³ãã«ãç½®ãã¦ããã¾ããç¨éã«ãããã¦åè¿°ã®å ´æã«ã³ãã¼ãã¦ä½¿ãããã§ããæ¡å¼µåã .conf ãããªã㦠.cnf ã§ããã©ãMacã ããï¼
# The following options will be passed to all MySQL clients [client] #password = your_password port = 9999 socket = /Applications/MAMP/tmp/mysql/mysql.sock # Here follows entries for some specific programs # The MySQL server [mysqld] port = 9999 socket = /Applications/MAMP/tmp/mysql/mysql.sock
ä¸ãè¦ãã¨ãã¼ãã MySQLããã©ã«ãã® 3306 ãããªã 9999 ã«æå®ããã¦ãã®ã§ããã®ã¾ã¾èªã¿è¾¼ã¾ããã¨å°ãããããã¾ããã
MAMP.app ã§è¨å®ãã MySQL ã®ãã¼ãçªå·ã¨ã®å ¼ãåãã¯ã©ããªããã ããï¼ã¨ãããããããã§ã®è¨å®ã my.conf ã«æ¸ãè¾¼ã¾ãããããããããªããã¨ããªãã¨ãªãæã£ã¦ããã©ãmy.conf ãç¡ãã®ã§ã©ãããäºãªãã ããï¼
MAMP MySQL ã®ã¯ã¨ãªã¼ãã£ãã·ã¥
mysql> SHOW VARIABLES LIKE 'have_query_cache'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | have_query_cache | YES | +------------------+-------+ 1 row in set (0.00 sec)
mysql> SHOW VARIABLES LIKE 'query_cache_size'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | query_cache_size | 0 | +------------------+-------+ 1 row in set (0.00 sec)
ãããªæãã§ãã¯ã¨ãªã¼ãã£ãã·ã¥ã¯å®è³ªç¡å¹ã®ããã§ã
/Applications/MAMP/Library/bin/mysql
ã¡ãªã¿ã«MAMPã®ã³ãã³ãã©ã¤ã³ã®ã¯ã©ã¤ã¢ã³ãã¯ããã«ããã¾ããmysqlc ãããªã㦠mysqlã
MySQLã®ã¯ã¨ãªã¼ãã£ãã·ã¥ãæå¹ã«ãã¦ã¿ã
mysql> SET GLOBAL query_cache_size = 41984; Query OK, 0 rows affected (0.00 sec) mysql> SHOW STATUS LIKE 'Qcache%'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | Qcache_free_blocks | 1 | | Qcache_free_memory | 33432 | | Qcache_hits | 0 | | Qcache_inserts | 0 | | Qcache_lowmem_prunes | 0 | | Qcache_not_cached | 1 | | Qcache_queries_in_cache | 0 | | Qcache_total_blocks | 1 | +-------------------------+-------+ 8 rows in set (0.00 sec)
ã¯ã¨ãªã¼ãã£ãã·ã¥ãæå¹ã«ããç´å¾ã®ã¯ã¨ãªã¼ãã£ãã·ã¥ã®ã¹ãã¼ã¿ã¹ã§ãã
ãããããCakePHPãã¼ã¹ã®ã¢ããªã®ãindexãã¼ã¸ã«ãã©ã¦ã¶ãã3åç¨ã¢ã¯ã»ã¹ãã¦ã¿ã¾ããã
mysql> SHOW STATUS LIKE 'Qcache%'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | Qcache_free_blocks | 2 | | Qcache_free_memory | 4408 | | Qcache_hits | 0 | | Qcache_inserts | 25 | | Qcache_lowmem_prunes | 11 | | Qcache_not_cached | 22 | | Qcache_queries_in_cache | 14 | | Qcache_total_blocks | 39 | +-------------------------+-------+ 8 rows in set (0.00 sec)
1åç®ãQcache_inserts ã 25ã«ãªãã¾ããã
mysql> SHOW STATUS LIKE 'Qcache%'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | Qcache_free_blocks | 1 | | Qcache_free_memory | 4072 | | Qcache_hits | 0 | | Qcache_inserts | 50 | | Qcache_lowmem_prunes | 36 | | Qcache_not_cached | 43 | | Qcache_queries_in_cache | 14 | | Qcache_total_blocks | 38 | +-------------------------+-------+ 8 rows in set (0.00 sec)
2åç®ãQcache_inserts ã50ã«ãªãã¾ãããä½æ ã Qcache_hits ãå¢ãã¾ããã
mysql> SHOW STATUS LIKE 'Qcache%'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | Qcache_free_blocks | 2 | | Qcache_free_memory | 4528 | | Qcache_hits | 0 | | Qcache_inserts | 75 | | Qcache_lowmem_prunes | 62 | | Qcache_not_cached | 64 | | Qcache_queries_in_cache | 13 | | Qcache_total_blocks | 37 | +-------------------------+-------+ 8 rows in set (0.00 sec)
3åç®ãQcache_inserts ã75ã«ãªãã¾ãããå¤ããã Qcache_hits ãå¢ãã¦ã¾ãããçç±ã¯åããã¾ããããã¯ã¨ãªã¼ãã£ãã·ã¥ãæå¹ã«ãã¦ããä½æ
ã使ããã¦ããªãããã§ãã
ã¡ãªã¿ã«ãecho $this->element('sql_dump'); ã®åºåçµæã25åã®SELECTæã確èªåºæ¥ãã®ã§ãQcache_inserts ã25ãã¤å¢ãã¦ãã®ã¯ãã£ã¦ã¾ãã