CakePHPã®ãã£ãã·ã¥æéãã³ã³ããã¼ã«ãã
CakePHP1.2.5ã使ã£ã¦ã¾ãã
ç¹ã«æ
å ±ãä¸å®æéå¤ãããªãã®ã«DBã¢ã¯ã»ã¹ãèµ°ããã¼ã¸ããTOPãã¼ã¸ã ã£ãããã¢ã¯ã»ã¹ãå¤ããã¼ã¸ã ã£ãå ´åããã£ãã·ã¥ã¯ããã©ã¼ãã³ã¹æ¹åã«æ群ã®å¹æãããã¾ãã
Cakeã®ãã£ãã·ã¥ã使ãã¨ãapp/tmp/cache以ä¸ã«ãã£ãã·ã¥ãã¡ã¤ã«ãä½ã£ã¦ããããåç §ãã¦DBã¢ã¯ã»ã¹ãåé¿ãããªãã¦ãã¨ãç°¡åã«ã§ãã¾ããCakeã®ãã£ãã·ã¥ã¯APCã使ã£ã¦ã¡ã¢ãªä¸ã«è¼ããã¨ããç°¡åã§ãã
ä»åã¯ãè¤æ°ãã¤ã³ãã§ãç°ãªããã£ãã·ã¥æéãæããããã¨ãã®Tipsã
core.phpã«ãã£ãã·ã¥ã使ãå®ç¾©ï¼ããã©ã«ãã®ã¾ã¾ï¼
Cache::config('default', array('engine' => 'File'));
ããã®å®ç¾©ããFileããApcã«ããã°ã¡ã¢ãªã«è¼ãããã§ãã¾ãã
ããã³ã³ããã¼ã©ã§ãã¢ãã«ã使ã£ã¦DBããèªã¿è¾¼ãã çµæï¼é åãã¼ã¿ï¼ã60ç§ãã£ãã·ã¥ããå ´å
<?php class PostController extends AppController { var $uses = array('Post'); function index() { $return_data = null; Cache::set(array('duration' => '+60 seconds')); if( ($return_data = Cache::read('PostController-index') ) === false ){ $return_data = $this->Post->find('all'); Cache::set(array('duration' => '+60 seconds')); Cache::write('PostController-index' , $return_data); } $this->set('data',$return_data); } }
ããããã¨1åç®ã®ã¢ã¯ã»ã¹ã§DBãããã¼ã¿ãåå¾ãããã®çµæã®é åãã¼ã¿ããapp/tmp/cache/PostController-indexã¨ãããã¡ã¤ã«ã«ã·ãªã¢ã©ã¤ãºãã¦åºåãã¾ãã60ç§ä»¥å ã«ã¢ã¯ã»ã¹ããã°ãã£ãã·ã¥ãã¼ã¿ãããã®ã§ããã£ãã·ã¥ãã¡ã¤ã«ã®å 容ãã$return_dataã«å ¥ãã¾ãã
åºæ¬ã¯ããã ãã§ããè¶
ç°¡åã便å©ï¼ 注æç¹ã¯ãCache::readã®åã¨ãCache::writeã®åã«ãããããCache::setã§ãã£ãã·ã¥æéãã»ããããå¿
è¦ããããã¨ã§ãããããããªãã¨ããã©ã«ãã®å¤ããã£ãã·ã¥æéã«ã»ããããã¦ãã¾ãã¾ãã
åç
§ï¼ãhttp://book.cakephp.org/ja/view/773/Cache-set
Cakeã®Cacheã¯ãã³ã³ããã¼ã©ãããªãã¦ããã¢ãã«ã§ãã©ãã§ã使ãã¾ãããé åãã¼ã¿ã§ãä½ã§ãçªã£è¾¼ããã®ã§ãã¨ã¦ã便å©ã§ãããä»ã®å ´æã§ã1æéã®ãã£ãã·ã¥ã使ãå ´åã¯ã
Cache::set(array('duration' => '+3600 seconds')); Cache::write('HogeModel-getData' , $return_data);
ããããã°OKã注æç¹ã¯ããã£ãã·ã¥ãã¡ã¤ã«åãéè¤ããªãããã«ãããã¨ãä¾ãã°ã¢ãã«/ã³ã³ããã¼ã©å-ã¡ã½ããå-ãã©ã¡ã¼ã¿ã¿ãããªã
durationã®æå®ã¯ãç§ãããªãã¦ãã+1 dayã¨ãã+2 hoursã¨ãã§ãããã¾ã
ä½è«ã§ãããCache::read,writeã¡ã½ããã«ã¯ãå¼æ°ã§configã®å¤ãã»ããã§ãã¾ãã
http://book.cakephp.org/ja/view/766/Cache-read
http://book.cakephp.org/ja/view/767/Cache-write
ããã使ãã¨ãcore.phpã«
Cache::config('default', array('engine' => 'File')); Cache::config('onemin', array('engine' => 'File','duration'=> 60,)); Cache::config('onehour', array('engine' => 'File','duration'=> 3600,));
ã¨ãã¦ãè¤æ°å®ç¾©ããã¦ããã°ãCache::read,writeæã«ãããæå®ããã ãã§ããã¾ãã
Cache::read('PostController-index', 'onemin') Cache::write('PostController-index' , $return_data,'onemin');
追è¨ï¼
è±èªããã°ã®æ¹ã§åãè¨äºãæ稿ããããã³ã¡ã³ããããã¾ããã
http://cake.eizoku.com/blog/?p=93#comments
ãã£ãã·ã¥ã®ãã¡ã¤ã«åã®éè¤ãé¿ãããã£ãããfindã®ãã©ã¡ã¼ã¿é
åãserializeãã¦md5ã«ããã¦ããããã¤ããã¨è¯ããã¨ãããã®ããã£ãã·ã¥ãã¡ã¤ã«åã¯ã
PostController-index-9e107d9d372bb6826bd81d3542a419d6
ãããªæãã«ãªãã
ã³ã¡ã³ããããäºäººã¯ãCakeFestã«æ¥ã¦ã人ã