{JA} - 7.2.4 コントローラでキャッシュする
キャッシュ機能を使用するコントローラは $helpers 配列で CacheHelper を読み込む必要があります。
var $helpers = array('Cache');
var $helpers = array('Cache');
アクションがキャッシュを必要としていることやどのくらいの間各アクションがキャッシュされるかを示す必要があります。コントローラの $cacheAction 変数で指定します。$cacheAction は配列を設定し、キャッシュさせるアクションやビューにキャッシュさせたい期間を秒単位で指定します。時間の値は strtotime() 形式で表現できます。(たとえば、"1 hour" や "3 minutes")
ArticlesController の例を使用します。多くのトラフィックを受けるのでキャシュが必要です。
キャッシュは異なる時間間隔で Articles を見ます。
var $cacheAction = array( 'view/23/' => 21600, 'view/48/' => 36000, 'view/52' => 48000 );
var $cacheAction = array('view/23/' => 21600,'view/48/' => 36000,'view/52' => 48000);
このような articles の広い範囲の場合、全アクションをキャッシュします。
var $cacheAction = array( 'archives/' => '60000' );
var $cacheAction = array('archives/' => '60000');
コントローラに渡るキャッシュ時間を表示するために strtotime() 形式の時間を使用してコントローラのアクション毎にキャッシュします。
var $cacheAction = "1 hour";
var $cacheAction = "1 hour";
{EN} - 7.2.4 Caching in the Controller
Any controllers that utilize caching functionality need to include the CacheHelper in their $helpers array.
var $helpers = array('Cache');
var $helpers = array('Cache');
You also need to indicate which actions need caching, and how long each action will be cached. This is done through the $cacheAction variable in your controllers. $cacheAction should be set to an array which contains the actions you want cached, and the duration in seconds you want those views cached. The time value can be expressed in a strtotime() format. (ie. "1 hour", or "3 minutes").
Using the example of an ArticlesController, that receives a lot of traffic that needs to be cached.
Cache frequently visited Articles for varying lengths of time
var $cacheAction = array( 'view/23' => 21600, 'view/48' => 36000, 'view/52' => 48000 );
var $cacheAction = array('view/23' => 21600,'view/48' => 36000,'view/52' => 48000);
Remember to use your routes in the $cacheAction if you have any.
Cache an entire action in this case a large listing of articles
var $cacheAction = array( 'archives/' => '60000' );
var $cacheAction = array('archives/' => '60000');
Cache every action in the controller using a strtotime() friendly time to indicate Controller wide caching time.
var $cacheAction = "1 hour";
var $cacheAction = "1 hour";
You can also enable controller/component callbacks for cached views created with CacheHelper. To do so you must use the array format for $cacheAction and create an array like the following:
var $cacheAction = array(
'view' => array('callbacks' => true, 'duration' => 21600),
'add' => array('callbacks' => true, 'duration' => 36000),
'index' => array('callbacks' => true, 'duration' => 48000)
);
var $cacheAction = array('view' => array('callbacks' => true, 'duration' => 21600),'add' => array('callbacks' => true, 'duration' => 36000),'index' => array('callbacks' => true, 'duration' => 48000));
By setting callbacks => true you tell CacheHelper that you want the generated files to create the components and models for the controller. As well as, fire the component initialize, controller beforeFilter, and component startup callbacks.
callbacks => true partly defeats the purpose of caching. This is also the reason it is disabled by default.
差分
| Lines: 1-35 | Lines: 1-24 | ||
| - | <title>Caching in the Controller</title> <p>Any controllers that utilize caching functionality need to include the CacheHelper in their $helpers array.</p> |
+ | <title>コントローラでキャッシュする</title> <p>キャッシュ機能を使用するコントローラは $helpers 配列で CacheHelper を読み込む必要があります。</p> |
| <pre> | <pre> | ||
| var $helpers = array('Cache'); | var $helpers = array('Cache'); | ||
| </pre> | </pre> | ||
| - | <p>You also need to indicate which actions need caching, and how long each action will be cached. This is done through the $cacheAction variable in your controllers. $cacheAction should be set to an array which contains the actions you want cached, and the duration in seconds you want those views cached. The time value can be expressed in a strtotime() format. (ie. "1 hour", or "3 minutes"). </p> <p>Using the example of an ArticlesController, that receives a lot of traffic that needs to be cached.</p> <p>Cache frequently visited Articles for varying lengths of time</p> |
+ | <p>アクションがキャッシュを必要としていることやどのくらいの間各アクションがキャッシュされるかを示す必要があります。コントローラの $cacheAction 変数で指定します。$cacheAction は配列を設定し、キャッシュさせるアクションやビューにキャッシュさせたい期間を秒単位で指定します。時間の値は strtotime() 形式で表現できます。(たとえば、"1 hour" や "3 minutes")</p> <p>ArticlesController の例を使用します。多くのトラフィックを受けるのでキャシュが必要です。</p> <p>キャッシュは異なる時間間隔で Articles を見ます。</p> |
| <pre> | <pre> | ||
| var $cacheAction = array( | var $cacheAction = array( | ||
| - | 'view/23' => 21600, 'view/48' => 36000, |
+ | 'view/23/' => 21600, 'view/48/' => 36000, |
| 'view/52' => 48000 | 'view/52' => 48000 | ||
| ); | ); | ||
| </pre> | </pre> | ||
| - | <p>Remember to use your routes in the $cacheAction if you have any.</p>r /><p>Cache an entire action in this case a large listing of articles</p> | + | <p>このような articles の広い範囲の場合、全アクションをキャッシュします。</p> |
| <pre> | <pre> | ||
| var $cacheAction = array( | var $cacheAction = array( | ||
| 'archives/' => '60000' | 'archives/' => '60000' | ||
| ); | ); | ||
| </pre> | </pre> | ||
| - | <p>Cache every action in the controller using a strtotime() friendly time to indicate Controller wide caching time.</p> | + | <p>コントローラに渡るキャッシュ時間を表示するために strtotime() 形式の時間を使用してコントローラのアクション毎にキャッシュします。</p> |
| <pre>var $cacheAction = "1 hour";</pre> | <pre>var $cacheAction = "1 hour";</pre> | ||
| - | <p>You can also enable controller/component callbacks for cached views created with <code>CacheHelper</code>. To do so you must use the array format for <code>$cacheAction</code> and create an array like the following: <pre> var $cacheAction = array( 'view' => array('callbacks' => true, 'duration' => 21600), 'add' => array('callbacks' => true, 'duration' => 36000), 'index' => array('callbacks' => true, 'duration' => 48000) ); </pre> <p>By setting <code>callbacks => true</code> you tell CacheHelper that you want the generated files to create the components and models for the controller. As well as, fire the component initialize, controller beforeFilter, and component startup callbacks.</p> <p class="note"Setting <code>callbacks => true</code> partly defeats the purpose of caching. This is also the reason it is disabled by default.</p> |
+ | |

