Zend_Cache-Frontends.xml 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <!-- EN-Revision: 15103 -->
  4. <sect1 id="zend.cache.frontends">
  5. <title><classname>Zend_Cache</classname> のフロントエンド</title>
  6. <sect2 id="zend.cache.frontends.core">
  7. <title>Zend_Cache_Core</title>
  8. <sect3 id="zend.cache.frontends.core.introduction">
  9. <title>導入</title>
  10. <para>
  11. <classname>Zend_Cache_Core</classname> は特別なフロントエンドであり、
  12. モジュールのコアに含まれています。これはキャッシュフロントエンドの
  13. 基本機能を実装したものであり、他のクラスによってオーバーライドされます。
  14. </para>
  15. <note><para>
  16. その他のフロントエンドクラスは、すべて <classname>Zend_Cache_Core</classname>
  17. を継承しており、以下で説明しているメソッドおよびオプションは
  18. 他のフロントエンドでも使用可能です。そのため、ここではこれらについての
  19. 詳しい説明は省略します。
  20. </para></note>
  21. </sect3>
  22. <sect3 id="zend.cache.frontends.core.options">
  23. <title>使用可能なオプション</title>
  24. <para>
  25. これらのオプションを、先の例で示したようにファクトリメソッドに渡します。
  26. </para>
  27. <table id="zend.cache.frontends.core.options.table">
  28. <title>Core フロントエンドのオプション</title>
  29. <tgroup cols="4">
  30. <thead>
  31. <row>
  32. <entry>オプション</entry>
  33. <entry>データ型</entry>
  34. <entry>デフォルト値</entry>
  35. <entry>説明</entry>
  36. </row>
  37. </thead>
  38. <tbody>
  39. <row>
  40. <entry><code>caching</code></entry>
  41. <entry><code>boolean</code></entry>
  42. <entry><code>true</code></entry>
  43. <entry>
  44. キャッシングを有効/無効にします
  45. (キャッシュされたスクリプトのデバッグ時に有用です)。
  46. </entry>
  47. </row>
  48. <row>
  49. <entry><code>cache_id_prefix</code></entry>
  50. <entry><code>string</code></entry>
  51. <entry><code>null</code></entry>
  52. <entry>
  53. すべてのキャッシュ ID のプレフィックス。<code>null</code> を指定すると、
  54. プレフィックスは使用しません。
  55. キャッシュ ID のプレフィックスは、いわばキャッシュ内での名前空間です。
  56. これによって、複数のアプリケーションやウェブサイトで
  57. キャッシュを共用できるようになります。
  58. 個々のアプリケーションやウェブサイトで
  59. それぞれ異なるキャッシュ ID プレフィックスを用いるようにすれば、
  60. 特定のキャッシュ ID をそれぞれの環境で使用できるようになります。
  61. </entry>
  62. </row>
  63. <row>
  64. <entry><code>lifetime</code></entry>
  65. <entry><code>int</code></entry>
  66. <entry><code>3600</code></entry>
  67. <entry>
  68. キャッシュの有効期間 (秒)。<code>null</code>
  69. を指定すると、有効期間が無期限となります。
  70. </entry>
  71. </row>
  72. <row>
  73. <entry><code>logging</code></entry>
  74. <entry><code>boolean</code></entry>
  75. <entry><code>false</code></entry>
  76. <entry>
  77. true を指定すると、<classname>Zend_Log</classname> によるロギングが有効になります
  78. (しかし、処理速度は低下します)。
  79. </entry>
  80. </row>
  81. <row>
  82. <entry><code>write_control</code></entry>
  83. <entry><code>boolean</code></entry>
  84. <entry><code>true</code></entry>
  85. <entry>
  86. 書き込み制御を有効/無効にします (壊れたエントリを検出するため、
  87. 書き込んだ直後にそのキャッシュを読み込みます)。
  88. writeControl を有効にすると、キャッシュの書き込みがやや遅くなりますが、
  89. 読み込みの速度は変わりません
  90. (これはキャッシュファイルが壊れているかどうかを調べるものですが、
  91. 完全に判断できるわけではありません)。
  92. </entry>
  93. </row>
  94. <row>
  95. <entry><code>automatic_serialization</code></entry>
  96. <entry><code>boolean</code></entry>
  97. <entry><code>false</code></entry>
  98. <entry>
  99. 自動シリアライズを有効/無効にします。
  100. 文字列でないデータを直接保存する際に使用します
  101. (しかし、処理速度は低下します)。
  102. </entry>
  103. </row>
  104. <row>
  105. <entry><code>automatic_cleaning_factor</code></entry>
  106. <entry><code>int</code></entry>
  107. <entry><code>10</code></entry>
  108. <entry>
  109. 自動クリーンアッププロセス (ガベージコレクタ) の設定を行います。
  110. 0 を指定すると、自動キャッシュクリーニングを行いません。
  111. 1 を指定すると計画的にキャッシュのクリーニングを行い、また
  112. x (1 より大きな整数) を指定すると、
  113. x 回のキャッシュ書き込みについて 1 回の頻度で
  114. ランダムに自動クリーニングを行います。
  115. </entry>
  116. </row>
  117. <row>
  118. <entry><code>ignore_user_abort</code></entry>
  119. <entry><code>boolean</code></entry>
  120. <entry><code>false</code></entry>
  121. <entry>
  122. true を指定すると、save() メソッド内で PHP の
  123. ignore_user_abort フラグを設定し、
  124. キャッシュが破壊されることを防ぎます。
  125. </entry>
  126. </row>
  127. </tbody>
  128. </tgroup>
  129. </table>
  130. </sect3>
  131. <sect3 id="zend.cache.core.examples">
  132. <title>例</title>
  133. <para>
  134. マニュアルのいちばんはじめのほうに、例を示しています。
  135. </para>
  136. <para>
  137. もしキャッシュに文字列しか保存しないのなら
  138. ("automatic_serialization" オプションを使用すると boolean も保存できるので)、
  139. このようにもう少しコンパクトに作成することが可能です。
  140. </para>
  141. <programlisting role="php"><![CDATA[
  142. // すでに $cache が存在するものとします
  143. $id = 'myBigLoop'; //「キャッシュしたい内容」のキャッシュ ID
  144. if (!($data = $cache->load($id))) {
  145. // キャッシュが存在しませんでした
  146. $data = '';
  147. for ($i = 0; $i < 10000; $i++) {
  148. $data = $data . $i;
  149. }
  150. $cache->save($data);
  151. }
  152. // [...] $data を用いて何かをします (echo したり、何かに渡したりなど)
  153. ]]>
  154. </programlisting>
  155. <para>
  156. 複数のブロックやデータのインスタンスをキャッシュしたい場合も、考え方は同じです。
  157. </para>
  158. <programlisting role="php"><![CDATA[
  159. // 一意な ID を使用するようにしましょう
  160. $id1 = 'foo';
  161. $id2 = 'bar';
  162. // ブロック 1
  163. if (!($data = $cache->load($id1))) {
  164. // キャッシュが存在しませんでした
  165. $data = '';
  166. for ($i=0;$i<10000;$i++) {
  167. $data = $data . $i;
  168. }
  169. $cache->save($data);
  170. }
  171. echo($data);
  172. // これは、キャッシュ処理の影響を受けません
  173. echo('キャッシュされません !');
  174. // ブロック 2
  175. if (!($data = $cache->load($id2))) {
  176. // キャッシュが存在しませんでした
  177. $data = '';
  178. for ($i=0;$i<10000;$i++) {
  179. $data = $data . '!';
  180. }
  181. $cache->save($data);
  182. }
  183. echo($data);
  184. ]]>
  185. </programlisting>
  186. <para>
  187. 特殊な値 (boolean 値に "automatic_serialization" オプションを指定したものなど)
  188. や空の文字列をキャッシュしたい場合は、
  189. 上で示したコンパクトな例を使用することはできません。
  190. キャッシュレコードを正式に調べる必要があります。
  191. </para>
  192. <programlisting role="php"><![CDATA[
  193. // コンパクトな構文
  194. // (空の文字列や boolean をキャッシュする場合はうまくいきません)
  195. if (!($data = $cache->load($id))) {
  196. // キャッシュが存在しませんでした
  197. // [...] $data を作成します
  198. $cache->save($data);
  199. }
  200. // $data に対して何らかの操作をします
  201. // [...]
  202. // 完全な構文 (どんな場合でも動作します)
  203. if (!($cache->test($id))) {
  204. // キャッシュが存在しませんでした
  205. // [...] $data を作成します
  206. $cache->save($data);
  207. } else {
  208. // キャッシュが見つかりました
  209. $data = $cache->load($id);
  210. }
  211. // $data に対して何らかの操作をします
  212. ]]>
  213. </programlisting>
  214. </sect3>
  215. </sect2>
  216. <sect2 id="zend.cache.frontends.output">
  217. <title><classname>Zend_Cache_Frontend_Output</classname></title>
  218. <sect3 id="zend.cache.frontends.output.introduction">
  219. <title>導入</title>
  220. <para>
  221. <classname>Zend_Cache_Frontend_Output</classname> は、出力を横取りするフロントエンドです。
  222. これは PHP の出力バッファリング処理を使いやすくしたもので、
  223. <code>start()</code> メソッドと
  224. <code>end()</code> メソッドの間の出力を横取りします。
  225. </para>
  226. </sect3>
  227. <sect3 id="zend.cache.frontends.output.options">
  228. <title>使用可能なオプション</title>
  229. <para>
  230. <classname>Zend_Cache_Core</classname> のオプション以外に、
  231. このフロントエンドが独自に使用するオプションはありません。
  232. </para>
  233. </sect3>
  234. <sect3 id="zend.cache.frontends.output.examples">
  235. <title>例</title>
  236. <para>
  237. このマニュアルの冒頭に示した例とほとんど同じですが、少しだけ変更を加えています。
  238. </para>
  239. <programlisting role="php"><![CDATA[
  240. // キャッシュが見つからなかった場合に、出力バッファリングが起動します
  241. if (!($cache->start('mypage'))) {
  242. // すべてをいつもどおりに出力しますoutput everything as usual
  243. echo 'Hello world! ';
  244. echo 'これはキャッシュされます ('.time().') ';
  245. $cache->end(); // 出力バッファリングを終了します
  246. }
  247. echo 'これはキャッシュされません ('.time().').';
  248. ]]>
  249. </programlisting>
  250. <para>
  251. この形式を使用すると、既存のプロジェクトに簡単に出力キャッシュ処理を追加することができます。
  252. コードのリファクタリングもほとんど行わずにすませられるでしょう。
  253. </para>
  254. </sect3>
  255. </sect2>
  256. <sect2 id="zend.cache.frontends.function">
  257. <title><classname>Zend_Cache_Frontend_Function</classname></title>
  258. <sect3 id="zend.cache.frontends.function.introduction">
  259. <title>導入</title>
  260. <para>
  261. <classname>Zend_Cache_Frontend_Function</classname> は、関数コールの結果をキャッシュします。
  262. <code>call()</code> というメソッドを保持しており、
  263. 関数名とパラメータを配列にしてこのメソッドに渡します。
  264. </para>
  265. </sect3>
  266. <sect3 id="zend.cache.frontends.function.options">
  267. <title>使用可能なオプション</title>
  268. <table id="zend.cache.frontends.function.options.table">
  269. <title>Function フロントエンドのオプション</title>
  270. <tgroup cols="4">
  271. <thead>
  272. <row>
  273. <entry>オプション</entry>
  274. <entry>データ型</entry>
  275. <entry>デフォルト値</entry>
  276. <entry>説明</entry>
  277. </row>
  278. </thead>
  279. <tbody>
  280. <row>
  281. <entry><code>cache_by_default</code></entry>
  282. <entry><code>boolean</code></entry>
  283. <entry><code>true</code></entry>
  284. <entry>
  285. true の場合は、関数のコール結果がデフォルトでキャッシュされます。
  286. </entry>
  287. </row>
  288. <row>
  289. <entry><code>cached_functions</code></entry>
  290. <entry><code>array</code></entry>
  291. <entry></entry>
  292. <entry>
  293. 常にキャッシュされる関数の名前。
  294. </entry>
  295. </row>
  296. <row>
  297. <entry><code>non_cached_functions</code></entry>
  298. <entry><code>array</code></entry>
  299. <entry></entry>
  300. <entry>
  301. 決してキャッシュされない関数の名前。
  302. </entry>
  303. </row>
  304. </tbody>
  305. </tgroup>
  306. </table>
  307. </sect3>
  308. <sect3 id="zend.cache.frontends.function.examples">
  309. <title>例</title>
  310. <para>
  311. <code>call()</code> 関数の使用法は、PHP の
  312. <code>call_user_func_array()</code> と同じです。
  313. </para>
  314. <programlisting role="php"><![CDATA[
  315. $cache->call('veryExpensiveFunc', $params);
  316. // $params は配列です。
  317. // 例えば、veryExpensiveFunc(1, 'foo', 'bar') のコールをキャッシュするには
  318. // $cache->call('veryExpensiveFunc', array(1, 'foo', 'bar')) とします。
  319. ]]>
  320. </programlisting>
  321. <para>
  322. <classname>Zend_Cache_Frontend_Function</classname> は、
  323. 関数の返り値だけでなく関数内部での出力もキャッシュします。
  324. </para>
  325. <note><para>
  326. <code>array()</code>、<code>echo()</code>、<code>empty()</code>、<code>eval()</code>、
  327. <code>exit()</code>、<code>isset()</code>、<code>list()</code>、<code>print()</code>
  328. および <code>unset()</code> 以外なら、
  329. 任意の組み込み関数やユーザ定義関数を渡すことができます。
  330. </para></note>
  331. </sect3>
  332. </sect2>
  333. <sect2 id="zend.cache.frontends.class">
  334. <title><classname>Zend_Cache_Frontend_Class</classname></title>
  335. <sect3 id="zend.cache.frontends.class.introduction">
  336. <title>導入</title>
  337. <para>
  338. <classname>Zend_Cache_Frontend_Class</classname> は、<classname>Zend_Cache_Frontend_Function</classname>
  339. と異なり、オブジェクトおよびスタティックメソッドのコールをキャッシュします。
  340. </para>
  341. </sect3>
  342. <sect3 id="zend.cache.frontends.class.options">
  343. <title>使用可能なオプション</title>
  344. <table id="zend.cache.frontends.class.options.table">
  345. <title>Class フロントエンドのオプション</title>
  346. <tgroup cols="4">
  347. <thead>
  348. <row>
  349. <entry>オプション</entry>
  350. <entry>データ型</entry>
  351. <entry>デフォルト値</entry>
  352. <entry>説明</entry>
  353. </row>
  354. </thead>
  355. <tbody>
  356. <row>
  357. <entry><code>cached_entity</code> (必須)</entry>
  358. <entry><code>mixed</code></entry>
  359. <entry></entry>
  360. <entry>
  361. クラス名を設定すると、抽象クラスおよびスタティックコールをキャッシュします。
  362. オブジェクトを設定すると、そのオブジェクトのメソッドをキャッシュします。
  363. </entry>
  364. </row>
  365. <row>
  366. <entry><code>cache_by_default</code></entry>
  367. <entry><code>boolean</code></entry>
  368. <entry><code>true</code></entry>
  369. <entry>
  370. true を設定すると、デフォルトでキャッシュされます。
  371. </entry>
  372. </row>
  373. <row>
  374. <entry><code>cached_methods</code></entry>
  375. <entry><code>array</code></entry>
  376. <entry></entry>
  377. <entry>
  378. 常にキャッシュされるメソッドの名前。
  379. </entry>
  380. </row>
  381. <row>
  382. <entry><code>non_cached_methods</code></entry>
  383. <entry><code>array</code></entry>
  384. <entry></entry>
  385. <entry>
  386. 決してキャッシュされないメソッドの名前。
  387. </entry>
  388. </row>
  389. </tbody>
  390. </tgroup>
  391. </table>
  392. </sect3>
  393. <sect3 id="zend.cache.frontends.class.examples">
  394. <title>例</title>
  395. <para>
  396. 例えば、スタティックメソッドのコールをキャッシュするには次のようにします。
  397. </para>
  398. <programlisting role="php"><![CDATA[
  399. class Test {
  400. // スタティックメソッド
  401. public static function foobar($param1, $param2) {
  402. echo "foobar_output($param1, $param2)";
  403. return "foobar_return($param1, $param2)";
  404. }
  405. }
  406. // [...]
  407. $frontendOptions = array(
  408. 'cached_entity' => 'Test' // クラス名を指定します
  409. );
  410. // [...]
  411. // これはキャッシュされます
  412. $result = $cache->foobar('1', '2');
  413. ]]>
  414. </programlisting>
  415. <para>
  416. 通常のメソッドのコールをキャッシュするには次のようにします。
  417. </para>
  418. <programlisting role="php"><![CDATA[
  419. class Test {
  420. private $_string = 'hello !';
  421. public function foobar2($param1, $param2) {
  422. echo($this->_string);
  423. echo "foobar2_output($param1, $param2)";
  424. return "foobar2_return($param1, $param2)";
  425. }
  426. }
  427. // [...]
  428. $frontendOptions = array(
  429. 'cached_entity' => new Test() // クラスのインスタンスを指定します
  430. );
  431. // [...]
  432. // これはキャッシュされます
  433. $result = $cache->foobar2('1', '2');
  434. ]]>
  435. </programlisting>
  436. </sect3>
  437. </sect2>
  438. <sect2 id="zend.cache.frontends.file">
  439. <title><classname>Zend_Cache_Frontend_File</classname></title>
  440. <sect3 id="zend.cache.frontends.file.introduction">
  441. <title>導入</title>
  442. <para>
  443. <classname>Zend_Cache_Frontend_File</classname> は、マスタファイルの
  444. 「更新時刻」にもとづいて動作するフロントエンドです。
  445. これは、例えば設定ファイルやテンプレートなどで有効に使えるでしょう。
  446. 複数のマスタファイルを使用することもできます。
  447. </para>
  448. <para>
  449. 例えば、XML の設定ファイルを使用しており、それが「設定オブジェクト」
  450. (<classname>Zend_Config</classname> など) を返す関数でパースされるとしましょう。
  451. <classname>Zend_Cache_Frontend_File</classname> を使用すると、その「設定オブジェクト」
  452. をキャッシュすることができ (これにより、
  453. XML ファイルを毎回パースする必要がなくなります)、さらに「マスタファイル」
  454. との間で強力な依存性を保持することができます。そのため、XML
  455. 設定ファイルが更新されると、即時にキャッシュが無効になります。
  456. </para>
  457. </sect3>
  458. <sect3 id="zend.cache.frontends.file.options">
  459. <title>使用可能なオプション</title>
  460. <table id="zend.cache.frontends.file.options.table">
  461. <title>File フロントエンドのオプション</title>
  462. <tgroup cols="4">
  463. <thead>
  464. <row>
  465. <entry>オプション</entry>
  466. <entry>データ型</entry>
  467. <entry>デフォルト値</entry>
  468. <entry>説明</entry>
  469. </row>
  470. </thead>
  471. <tbody>
  472. <row>
  473. <entry><code>master_file (非推奨)</code></entry>
  474. <entry><code>string</code></entry>
  475. <entry><code></code></entry>
  476. <entry>
  477. マスタファイルへのフルパス。
  478. </entry>
  479. </row>
  480. <row>
  481. <entry><code>master_files</code></entry>
  482. <entry><code>array</code></entry>
  483. <entry><code></code></entry>
  484. <entry>
  485. マスタファイル群へのフルパスの配列。
  486. </entry>
  487. </row>
  488. <row>
  489. <entry><code>master_files_mode</code></entry>
  490. <entry><code>string</code></entry>
  491. <entry><classname>Zend_Cache_Frontend_File::MODE_OR</classname></entry>
  492. <entry>
  493. <classname>Zend_Cache_Frontend_File::MODE_AND</classname> あるいは
  494. <classname>Zend_Cache_Frontend_File::MODE_OR</classname>。
  495. <code>MODE_AND</code> の場合は、
  496. すべてのマスタファイルにアクセスがあるまでキャッシュが無効化されません。
  497. <code>MODE_OR</code> の場合は、
  498. どれかひとつのマスタファイルにアクセスがあればキャッシュを無効化します。
  499. </entry>
  500. </row>
  501. <row>
  502. <entry><code>ignore_missing_master_files</code></entry>
  503. <entry><code>boolean</code></entry>
  504. <entry><code>false</code></entry>
  505. <entry>
  506. true の場合は、マスタファイルが存在しない場合は無視します
  507. (true でない場合は例外が発生します)。
  508. </entry>
  509. </row>
  510. </tbody>
  511. </tgroup>
  512. </table>
  513. </sect3>
  514. <sect3 id="zend.cache.frontends.file.examples">
  515. <title>例</title>
  516. <para>
  517. このフロントエンドの使用法は <classname>Zend_Cache_Core</classname> と同じです。
  518. そのため、特に例は用意していません。唯一しなければならないことは、
  519. ファクトリを使用する際に、バックエンドのオプションとして
  520. <code>master_file</code> を設定することだけです。
  521. </para>
  522. </sect3>
  523. </sect2>
  524. <sect2 id="zend.cache.frontends.page">
  525. <title><classname>Zend_Cache_Frontend_Page</classname></title>
  526. <sect3 id="zend.cache.frontends.page.introduction">
  527. <title>導入</title>
  528. <para>
  529. <classname>Zend_Cache_Frontend_Page</classname> は <classname>Zend_Cache_Frontend_Output</classname>
  530. と似ていますが、ページ全体をキャッシュする目的で設計されています。
  531. <classname>Zend_Cache_Frontend_Page</classname> を使用して、
  532. ページの一部だけをキャッシュすることはできません。
  533. </para>
  534. <para>
  535. 一方、「キャッシュ ID」は自動的に生成されます。この ID は、
  536. <code>$_SERVER['REQUEST_URI']</code> および (オプションの設定によっては)
  537. <code>$_GET</code>、<code>$_POST</code>、<code>$_SESSION</code>、
  538. <code>$_COOKIE</code>、<code>$_FILES</code> をもとにして生成されます。
  539. さらに、ひとつのメソッド (<code>start()</code>) をコールするだけで使用できます。
  540. <code>end()</code> は、ページの終了時に自動的にコールされます。
  541. </para>
  542. <para>
  543. 現時点ではまだ実装されていませんが、将来は HTTP conditional システムを追加する予定です。
  544. これにより、ネットワークの帯域を節約できるようになります
  545. (キャッシュにヒットし、かつブラウザがそのバージョンを既に持っている場合に
  546. HTTP 304 Not Modified を送信するようにします)。
  547. </para>
  548. </sect3>
  549. <sect3 id="zend.cache.frontends.page.options">
  550. <title>使用可能なオプション</title>
  551. <table id="zend.cache.frontends.page.options.table">
  552. <title>Page フロントエンドのオプション</title>
  553. <tgroup cols="4">
  554. <thead>
  555. <row>
  556. <entry>オプション</entry>
  557. <entry>データ型</entry>
  558. <entry>デフォルト値</entry>
  559. <entry>説明</entry>
  560. </row>
  561. </thead>
  562. <tbody>
  563. <row>
  564. <entry><code>http_conditional</code></entry>
  565. <entry><code>boolean</code></entry>
  566. <entry><code>false</code></entry>
  567. <entry>
  568. http_conditional システムを使用します (現時点ではまだ実装されていません)。
  569. </entry>
  570. </row>
  571. <row>
  572. <entry><code>debug_header</code></entry>
  573. <entry><code>boolean</code></entry>
  574. <entry><code>false</code></entry>
  575. <entry>
  576. true の場合は、キャッシュされた各ページの先頭に
  577. デバッグ用テキストが追加されます。
  578. </entry>
  579. </row>
  580. <row>
  581. <entry><code>default_options</code></entry>
  582. <entry><code>array</code></entry>
  583. <entry><code>array(...説明を参照ください...)</code></entry>
  584. <entry>
  585. デフォルトのオプションを表す連想配列です。
  586. <itemizedlist>
  587. <listitem>
  588. <para>
  589. <code>(boolean, デフォルトは true) cache</code> :
  590. true の場合はキャッシュが有効になります。
  591. </para>
  592. </listitem>
  593. <listitem>
  594. <para>
  595. <code>(boolean, デフォルトは false) cache_with_get_variables</code> :
  596. true の場合は、<code>$_GET</code> 配列に変数が含まれていてもキャッシュがオンのままになります。
  597. </para>
  598. </listitem>
  599. <listitem>
  600. <para>
  601. <code>(boolean, デフォルトは false) cache_with_post_variables</code> :
  602. true の場合は、<code>$_POST</code> 配列に変数が含まれていてもキャッシュがオンのままになります。
  603. </para>
  604. </listitem>
  605. <listitem>
  606. <para>
  607. <code>(boolean, デフォルトは false) cache_with_session_variables</code> :
  608. true の場合は、<code>$_SESSION</code> 配列に変数が含まれていてもキャッシュがオンのままになります。
  609. </para>
  610. </listitem>
  611. <listitem>
  612. <para>
  613. <code>(boolean, デフォルトは false) cache_with_files_variables</code> :
  614. true の場合は、<code>$_FILES</code> 配列に変数が含まれていてもキャッシュがオンのままになります。
  615. </para>
  616. </listitem>
  617. <listitem>
  618. <para>
  619. <code>(boolean, デフォルトは false) cache_with_cookie_variables</code> :
  620. true の場合は、<code>$_COOKIE</code> 配列に変数が含まれていてもキャッシュがオンのままになります。
  621. </para>
  622. </listitem>
  623. <listitem>
  624. <para>
  625. <code>(boolean, デフォルトは true) make_id_with_get_variables</code> :
  626. true の場合は、キャッシュ ID が <code>$_GET</code> 配列の内容に依存するようになります。
  627. </para>
  628. </listitem>
  629. <listitem>
  630. <para>
  631. <code>(boolean, デフォルトは true) make_id_with_post_variables</code> :
  632. true の場合は、キャッシュ ID が <code>$_POST</code> 配列の内容に依存するようになります。
  633. </para>
  634. </listitem>
  635. <listitem>
  636. <para>
  637. <code>(boolean, デフォルトは true) make_id_with_session_variables</code> :
  638. true の場合は、キャッシュ ID が <code>$_SESSION</code> 配列の内容に依存するようになります。
  639. </para>
  640. </listitem>
  641. <listitem>
  642. <para>
  643. <code>(boolean, デフォルトは true) make_id_with_files_variables</code> :
  644. true の場合は、キャッシュ ID が <code>$_FILES</code> 配列の内容に依存するようになります。
  645. </para>
  646. </listitem>
  647. <listitem>
  648. <para>
  649. <code>(boolean, デフォルトは true) make_id_with_cookie_variables</code> :
  650. true の場合は、キャッシュ ID が <code>$_COOKIE</code> 配列の内容に依存するようになります。
  651. </para>
  652. </listitem>
  653. <listitem>
  654. <para>
  655. <code>(int, デフォルトは false) specific_lifetime</code> :
  656. false でない場合は、選択した正規表現に対して指定した有効期限を使用します。
  657. </para>
  658. </listitem>
  659. <listitem>
  660. <para>
  661. <code>(配列, デフォルトは array()) tags</code> :
  662. キャッシュレコード用のタグ。
  663. </para>
  664. </listitem>
  665. <listitem>
  666. <para>
  667. <code>(int, デフォルトは null) priority</code> :
  668. 優先度 (バックエンドが優先度をサポートしている場合)。
  669. </para>
  670. </listitem>
  671. </itemizedlist>
  672. </entry>
  673. </row>
  674. <row>
  675. <entry><code>regexps</code></entry>
  676. <entry><code>array</code></entry>
  677. <entry><code>array()</code></entry>
  678. <entry>
  679. 特定の REQUEST_URI に対してのみ適用するオプションを設定する連想配列です。
  680. キーが (PCRE の) 正規表現、対応する値は連想配列となります。
  681. この連想配列には、正規表現が $_SERVER['REQUEST_URI']
  682. にマッチした場合に設定されるオプションを設定します
  683. (使用可能なオプションについては default_options を参照ください)。
  684. 複数の正規表現が $_SERVER['REQUEST_URI'] にマッチした場合は、
  685. 一番最後にマッチしたもののみが使用されます。
  686. </entry>
  687. </row>
  688. <row>
  689. <entry><code>memorize_headers</code></entry>
  690. <entry><code>array</code></entry>
  691. <entry><code>array()</code></entry>
  692. <entry>
  693. HTTP ヘッダ名に対応する文字列の配列です。
  694. ここにあげられたヘッダがキャッシュデータとともに保存され、
  695. キャッシュにヒットしたときにそれが "リプレイ" されます。
  696. </entry>
  697. </row>
  698. </tbody>
  699. </tgroup>
  700. </table>
  701. </sect3>
  702. <sect3 id="zend.cache.frontends.page.examples">
  703. <title>例</title>
  704. <para>
  705. <classname>Zend_Cache_Frontend_Page</classname> の使用法は、きわめて簡単です。
  706. </para>
  707. <programlisting role="php"><![CDATA[
  708. // [...] // require、設定そしてファクトリ
  709. $cache->start();
  710. // キャッシュにヒットした場合はその結果がブラウザに送信され、
  711. // 処理はここで停止します
  712. // ページの残りの部分 ...
  713. ]]>
  714. </programlisting>
  715. <para>
  716. もう少し複雑な例を見てみましょう。これは、起動ファイル
  717. (例えば <classname>Zend_Controller</classname> など) 内でキャッシュを集中管理する方法を示したものです。
  718. </para>
  719. <programlisting role="php"><![CDATA[
  720. /*
  721. * キャッシュセクションの前には、あまり多くの行を書かないようにしましょう。
  722. * 例えば、処理速度を最適化するためには "require_once" や "Zend_Loader::loadClass"
  723. * をキャッシュセクションの後におくべきです。
  724. */
  725. $frontendOptions = array(
  726. 'lifetime' => 7200,
  727. 'debug_header' => true, // デバッグします
  728. 'regexps' => array(
  729. // IndexController 全体をキャッシュします
  730. '^/$' => array('cache' => true),
  731. // IndexController 全体をキャッシュします
  732. '^/index/' => array('cache' => true),
  733. // ArticleController はキャッシュしません
  734. '^/article/' => array('cache' => false),
  735. // ……が、ArticleController の "view" アクションはキャッシュします
  736. '^/article/view/' => array(
  737. 'cache' => true,
  738. // また、たとえ $_POST に何らかの変数がふくまれていてもキャッシュを行います
  739. 'cache_with_post_variables' => true,
  740. // しかし、そのキャッシュは $_POST 配列に依存します
  741. 'make_id_with_post_variables' => true
  742. )
  743. )
  744. );
  745. $backendOptions = array(
  746. 'cache_dir' => '/tmp/'
  747. );
  748. // Zend_Cache_Frontend_Page オブジェクトを取得します
  749. $cache = Zend_Cache::factory('Page',
  750. 'File',
  751. $frontendOptions,
  752. $backendOptions);
  753. $cache->start();
  754. // キャッシュにヒットした場合はその結果がブラウザに送信され、スクリプトの処理はここで停止します。
  755. // [...] 起動ファイルの終点 (これらの行は、キャッシュにヒットした場合は実行されません)
  756. ]]>
  757. </programlisting>
  758. </sect3>
  759. <sect3 id="zend.cache.frontends.page.cancel">
  760. <title>キャンセル用のメソッド</title>
  761. <para>
  762. 設計上の理由から、場合によっては (HTTP/200 以外のコードを使用する場合など)
  763. 現在のキャッシュ処理をキャンセルする必要が生じることもあります。
  764. そこで、このフロントエンド用に cancel() メソッドを用意しました。
  765. </para>
  766. <programlisting role="php"><![CDATA[
  767. // [...] // require, configuration そして factory
  768. $cache->start();
  769. // [...]
  770. if ($someTest) {
  771. $cache->cancel();
  772. // [...]
  773. }
  774. // [...]
  775. ]]>
  776. </programlisting>
  777. </sect3>
  778. </sect2>
  779. </sect1>
  780. <!--
  781. vim:se ts=4 sw=4 et:
  782. -->