私はそれがあなたのために働くと思います:
最新バージョンのcakephpを使用していると仮定して、これを次のcore.phpのCache.checkを構成する行に追加します。
例とコード:
/**
* Enable cache checking.
*
* If set to true, for view caching you must still use the controller
* public $cacheAction inside your controllers to define caching settings.
* You can either set it controller-wide by setting public $cacheAction = true,
* or in each action using $this->cacheAction = true.
*
*/
// Configure::write('Cache.check', true);
$UAs = array(
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.101 Safari/537.11'
);
if (in_array(env('HTTP_USER_AGENT'), $UAs)) {
define('USE_CACHE', '1 hour');
Configure::write('Cache.check', true);
} else {
define('USE_CACHE', false);
Configure::write('Cache.check', false);
}
$ UAsは、ボットのユーザーエージェントを指します
これは、コードのテストに使用できるサンプルコントローラーです。
<?php
App::uses('AppController', 'Controller');
class HomeController extends AppController {
public $name = 'Home';
public $uses = array();
public $helpers = array(
'Cache'
);
public $cacheAction = USE_CACHE;
public function index() {}
}