Zend_Cache-Frontends.xml 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.cache.frontends">
  4. <title>Zend_Cache Frontends</title>
  5. <sect2 id="zend.cache.frontends.core">
  6. <title>Zend_Cache_Core</title>
  7. <sect3 id="zend.cache.frontends.core.introduction">
  8. <title>Introduction</title>
  9. <para>
  10. <classname>Zend_Cache_Core</classname> is a special frontend because it is the core
  11. of the module. It is a generic cache frontend and is extended by other classes.
  12. </para>
  13. <note><para>
  14. All frontends inherit from <classname>Zend_Cache_Core</classname> so that its methods and options
  15. (described below) would also be available in other frontends, therefore they won't be
  16. documented there.
  17. </para></note>
  18. </sect3>
  19. <sect3 id="zend.cache.frontends.core.options">
  20. <title>Available options</title>
  21. <para>
  22. These options are passed to the factory method as demonstrated in previous examples.
  23. </para>
  24. <table id="zend.cache.frontends.core.options.table">
  25. <title>Core Frontend Options</title>
  26. <tgroup cols="4">
  27. <thead>
  28. <row>
  29. <entry>Option</entry>
  30. <entry>Data Type</entry>
  31. <entry>Default Value</entry>
  32. <entry>Description</entry>
  33. </row>
  34. </thead>
  35. <tbody>
  36. <row>
  37. <entry><code>caching</code></entry>
  38. <entry><code>boolean</code></entry>
  39. <entry><code>true</code></entry>
  40. <entry>
  41. enable / disable caching (can be very useful for the debug of
  42. cached scripts)
  43. </entry>
  44. </row>
  45. <row>
  46. <entry><code>cache_id_prefix</code></entry>
  47. <entry><code>string</code></entry>
  48. <entry><code>null</code></entry>
  49. <entry>
  50. A prefix for all cache ids, if set to <code>null</code>, no
  51. cache id prefix will be used. The cache id prefix essentially creates
  52. a namespace in the cache, allowing multiple applications or websites
  53. to use a shared cache. Each application or website can use a different
  54. cache id prefix so specific cache ids can be used more than once.
  55. </entry>
  56. </row>
  57. <row>
  58. <entry><code>lifetime</code></entry>
  59. <entry><code>int</code></entry>
  60. <entry><code>3600</code></entry>
  61. <entry>
  62. cache lifetime (in seconds), if set to <code>null</code>, the
  63. cache is valid forever.
  64. </entry>
  65. </row>
  66. <row>
  67. <entry><code>logging</code></entry>
  68. <entry><code>boolean</code></entry>
  69. <entry><code>false</code></entry>
  70. <entry>
  71. if set to true, logging through <classname>Zend_Log</classname> is activated
  72. (but the system is slower)
  73. </entry>
  74. </row>
  75. <row>
  76. <entry><code>write_control</code></entry>
  77. <entry><code>boolean</code></entry>
  78. <entry><code>true</code></entry>
  79. <entry>
  80. Enable / disable write control (the cache is read
  81. just after writing to detect corrupt entries), enabling write_control
  82. will lightly slow the cache writing but not the cache reading (it
  83. can detect some corrupt cache files but it's not a perfect control)
  84. </entry>
  85. </row>
  86. <row>
  87. <entry><code>automatic_serialization</code></entry>
  88. <entry><code>boolean</code></entry>
  89. <entry><code>false</code></entry>
  90. <entry>
  91. Enable / disable automatic serialization, it can be used to save directly datas
  92. which aren't strings (but it's slower)
  93. </entry>
  94. </row>
  95. <row>
  96. <entry><code>automatic_cleaning_factor</code></entry>
  97. <entry><code>int</code></entry>
  98. <entry><code>10</code></entry>
  99. <entry>
  100. Disable / Tune the automatic cleaning process (garbage collector):
  101. 0 means no automatic cache cleaning, 1 means systematic cache cleaning
  102. and x &gt; 1 means automatic random cleaning 1 times in x write operations.
  103. </entry>
  104. </row>
  105. <row>
  106. <entry><code>ignore_user_abort</code></entry>
  107. <entry><code>boolean</code></entry>
  108. <entry><code>false</code></entry>
  109. <entry>
  110. if set to true, the core will set the ignore_user_abort PHP flag inside the
  111. save() method to avoid cache corruptions in some cases
  112. </entry>
  113. </row>
  114. </tbody>
  115. </tgroup>
  116. </table>
  117. </sect3>
  118. <sect3 id="zend.cache.core.examples">
  119. <title>Examples</title>
  120. <para>
  121. An example is given in the manual at the very beginning.
  122. </para>
  123. <para>
  124. If you store only strings into cache (because with "automatic_serialization" option, it's possible
  125. to store some booleans), you can use a more compact construction like:
  126. </para>
  127. <programlisting role="php"><![CDATA[
  128. // we assume you already have $cache
  129. $id = 'myBigLoop'; // cache id of "what we want to cache"
  130. if (!($data = $cache->load($id))) {
  131. // cache miss
  132. $data = '';
  133. for ($i = 0; $i < 10000; $i++) {
  134. $data = $data . $i;
  135. }
  136. $cache->save($data);
  137. }
  138. // [...] do something with $data (echo it, pass it on etc.)
  139. ]]></programlisting>
  140. <para>
  141. If you want to cache multiple blocks or data instances, the idea is the same:
  142. </para>
  143. <programlisting role="php"><![CDATA[
  144. // make sure you use unique identifiers:
  145. $id1 = 'foo';
  146. $id2 = 'bar';
  147. // block 1
  148. if (!($data = $cache->load($id1))) {
  149. // cache missed
  150. $data = '';
  151. for ($i=0;$i<10000;$i++) {
  152. $data = $data . $i;
  153. }
  154. $cache->save($data);
  155. }
  156. echo($data);
  157. // this isn't affected by caching
  158. echo('NEVER CACHED! ');
  159. // block 2
  160. if (!($data = $cache->load($id2))) {
  161. // cache missed
  162. $data = '';
  163. for ($i=0;$i<10000;$i++) {
  164. $data = $data . '!';
  165. }
  166. $cache->save($data);
  167. }
  168. echo($data);
  169. ]]></programlisting>
  170. <para>
  171. If you want to cache special values (boolean with "automatic_serialization" option) or empty
  172. strings you can't use the compact construction given above. You have to test formally the
  173. cache record.
  174. </para>
  175. <programlisting role="php"><![CDATA[
  176. // the compact construction
  177. // (not good if you cache empty strings and/or booleans)
  178. if (!($data = $cache->load($id))) {
  179. // cache missed
  180. // [...] we make $data
  181. $cache->save($data);
  182. }
  183. // we do something with $data
  184. // [...]
  185. // the complete construction (works in any case)
  186. if (!($cache->test($id))) {
  187. // cache missed
  188. // [...] we make $data
  189. $cache->save($data);
  190. } else {
  191. // cache hit
  192. $data = $cache->load($id);
  193. }
  194. // we do something with $data
  195. ]]></programlisting>
  196. </sect3>
  197. </sect2>
  198. <sect2 id="zend.cache.frontends.output">
  199. <title>Zend_Cache_Frontend_Output</title>
  200. <sect3 id="zend.cache.frontends.output.introduction">
  201. <title>Introduction</title>
  202. <para>
  203. <classname>Zend_Cache_Frontend_Output</classname> is an output-capturing frontend. It utilizes
  204. output buffering in PHP to capture everything between its <code>start()</code> and
  205. <code>end()</code> methods.
  206. </para>
  207. </sect3>
  208. <sect3 id="zend.cache.frontends.output.options">
  209. <title>Available Options</title>
  210. <para>
  211. This frontend doesn't have any specific options other than those of
  212. <classname>Zend_Cache_Core</classname>.
  213. </para>
  214. </sect3>
  215. <sect3 id="zend.cache.frontends.output.examples">
  216. <title>Examples</title>
  217. <para>
  218. An example is given in the manual at the very beginning. Here it is with minor changes:
  219. </para>
  220. <programlisting role="php"><![CDATA[
  221. // if it is a cache miss, output buffering is triggered
  222. if (!($cache->start('mypage'))) {
  223. // output everything as usual
  224. echo 'Hello world! ';
  225. echo 'This is cached ('.time().') ';
  226. $cache->end(); // output buffering ends
  227. }
  228. echo 'This is never cached ('.time().').';
  229. ]]></programlisting>
  230. <para>
  231. Using this form it is fairly easy to set up output caching in your already working project
  232. with little or no code refactoring.
  233. </para>
  234. </sect3>
  235. </sect2>
  236. <sect2 id="zend.cache.frontends.function">
  237. <title>Zend_Cache_Frontend_Function</title>
  238. <sect3 id="zend.cache.frontends.function.introduction">
  239. <title>Introduction</title>
  240. <para>
  241. <classname>Zend_Cache_Frontend_Function</classname> caches the results of function calls. It has
  242. a single main method named <code>call()</code> which takes a function name and parameters
  243. for the call in an array.
  244. </para>
  245. </sect3>
  246. <sect3 id="zend.cache.frontends.function.options">
  247. <title>Available Options</title>
  248. <table id="zend.cache.frontends.function.options.table">
  249. <title>Function Frontend Options</title>
  250. <tgroup cols="4">
  251. <thead>
  252. <row>
  253. <entry>Option</entry>
  254. <entry>Data Type</entry>
  255. <entry>Default Value</entry>
  256. <entry>Description</entry>
  257. </row>
  258. </thead>
  259. <tbody>
  260. <row>
  261. <entry><code>cache_by_default</code></entry>
  262. <entry><code>boolean</code></entry>
  263. <entry><code>true</code></entry>
  264. <entry>
  265. if true, function calls will be cached by default
  266. </entry>
  267. </row>
  268. <row>
  269. <entry><code>cached_functions</code></entry>
  270. <entry><code>array</code></entry>
  271. <entry></entry>
  272. <entry>
  273. function names which will always be cached
  274. </entry>
  275. </row>
  276. <row>
  277. <entry><code>non_cached_functions</code></entry>
  278. <entry><code>array</code></entry>
  279. <entry></entry>
  280. <entry>
  281. function names which must never be cached
  282. </entry>
  283. </row>
  284. </tbody>
  285. </tgroup>
  286. </table>
  287. </sect3>
  288. <sect3 id="zend.cache.frontends.function.examples">
  289. <title>Examples</title>
  290. <para>
  291. Using the <code>call()</code> function is the same as using
  292. <code>call_user_func_array()</code> in PHP:
  293. </para>
  294. <programlisting role="php"><![CDATA[
  295. $cache->call('veryExpensiveFunc', $params);
  296. // $params is an array
  297. // For example to call veryExpensiveFunc(1, 'foo', 'bar') with
  298. // caching, you can use
  299. // $cache->call('veryExpensiveFunc', array(1, 'foo', 'bar'))
  300. ]]></programlisting>
  301. <para>
  302. <classname>Zend_Cache_Frontend_Function</classname> is smart enough to cache both the
  303. return value of the function and its internal output.
  304. </para>
  305. <note><para>
  306. You can pass any built in or user defined function with the exception of
  307. <code>array()</code>, <code>echo()</code>, <code>empty()</code>, <code>eval()</code>,
  308. <code>exit()</code>, <code>isset()</code>, <code>list()</code>, <code>print()</code>
  309. and <code>unset()</code>.
  310. </para></note>
  311. </sect3>
  312. </sect2>
  313. <sect2 id="zend.cache.frontends.class">
  314. <title>Zend_Cache_Frontend_Class</title>
  315. <sect3 id="zend.cache.frontends.class.introduction">
  316. <title>Introduction</title>
  317. <para>
  318. <classname>Zend_Cache_Frontend_Class</classname> is different from <classname>Zend_Cache_Frontend_Function</classname>
  319. because it allows caching of object and static method calls.
  320. </para>
  321. </sect3>
  322. <sect3 id="zend.cache.frontends.class.options">
  323. <title>Available Options</title>
  324. <table id="zend.cache.frontends.class.options.table">
  325. <title>Class Frontend Options</title>
  326. <tgroup cols="4">
  327. <thead>
  328. <row>
  329. <entry>Option</entry>
  330. <entry>Data Type</entry>
  331. <entry>Default Value</entry>
  332. <entry>Description</entry>
  333. </row>
  334. </thead>
  335. <tbody>
  336. <row>
  337. <entry><code>cached_entity</code> (required)</entry>
  338. <entry><code>mixed</code></entry>
  339. <entry></entry>
  340. <entry>
  341. if set to a class name, we will cache an abstract class and will use
  342. only static calls; if set to an object, we will cache this object methods
  343. </entry>
  344. </row>
  345. <row>
  346. <entry><code>cache_by_default</code></entry>
  347. <entry><code>boolean</code></entry>
  348. <entry><code>true</code></entry>
  349. <entry>
  350. if true, calls will be cached by default
  351. </entry>
  352. </row>
  353. <row>
  354. <entry><code>cached_methods</code></entry>
  355. <entry><code>array</code></entry>
  356. <entry></entry>
  357. <entry>
  358. method names which will always be cached
  359. </entry>
  360. </row>
  361. <row>
  362. <entry><code>non_cached_methods</code></entry>
  363. <entry><code>array</code></entry>
  364. <entry></entry>
  365. <entry>
  366. method names which must never be cached
  367. </entry>
  368. </row>
  369. </tbody>
  370. </tgroup>
  371. </table>
  372. </sect3>
  373. <sect3 id="zend.cache.frontends.class.examples">
  374. <title>Examples</title>
  375. <para>
  376. For example, to cache static calls :
  377. </para>
  378. <programlisting role="php"><![CDATA[
  379. class Test {
  380. // Static method
  381. public static function foobar($param1, $param2) {
  382. echo "foobar_output($param1, $param2)";
  383. return "foobar_return($param1, $param2)";
  384. }
  385. }
  386. // [...]
  387. $frontendOptions = array(
  388. 'cached_entity' => 'Test' // The name of the class
  389. );
  390. // [...]
  391. // The cached call
  392. $result = $cache->foobar('1', '2');
  393. ]]></programlisting>
  394. <para>
  395. To cache classic method calls :
  396. </para>
  397. <programlisting role="php"><![CDATA[
  398. class Test {
  399. private $_string = 'hello !';
  400. public function foobar2($param1, $param2) {
  401. echo($this->_string);
  402. echo "foobar2_output($param1, $param2)";
  403. return "foobar2_return($param1, $param2)";
  404. }
  405. }
  406. // [...]
  407. $frontendOptions = array(
  408. 'cached_entity' => new Test() // An instance of the class
  409. );
  410. // [...]
  411. // The cached call
  412. $result = $cache->foobar2('1', '2');
  413. ]]></programlisting>
  414. </sect3>
  415. </sect2>
  416. <sect2 id="zend.cache.frontends.file">
  417. <title>Zend_Cache_Frontend_File</title>
  418. <sect3 id="zend.cache.frontends.file.introduction">
  419. <title>Introduction</title>
  420. <para>
  421. <classname>Zend_Cache_Frontend_File</classname> is a frontend driven by the
  422. modification time of a "master file". It's really interesting for examples
  423. in configuration or templates issues. It's also possible to use multiple
  424. master files.
  425. </para>
  426. <para>
  427. For instance, you have an XML configuration file which is parsed by a function
  428. which returns a "config object" (like with <classname>Zend_Config</classname>). With
  429. <classname>Zend_Cache_Frontend_File</classname>, you can store the "config object" into
  430. cache (to avoid the parsing of the XML config file at each time) but with a
  431. sort of strong dependency on the "master file". So, if the XML config file
  432. is modified, the cache is immediately invalidated.
  433. </para>
  434. </sect3>
  435. <sect3 id="zend.cache.frontends.file.options">
  436. <title>Available Options</title>
  437. <table id="zend.cache.frontends.file.options.table">
  438. <title>File Frontend Options</title>
  439. <tgroup cols="4">
  440. <thead>
  441. <row>
  442. <entry>Option</entry>
  443. <entry>Data Type</entry>
  444. <entry>Default Value</entry>
  445. <entry>Description</entry>
  446. </row>
  447. </thead>
  448. <tbody>
  449. <row>
  450. <entry><code>master_file (deprecated)</code></entry>
  451. <entry><code>string</code></entry>
  452. <entry><code></code></entry>
  453. <entry>
  454. the complete path and name of the master file
  455. </entry>
  456. </row>
  457. <row>
  458. <entry><code>master_files</code></entry>
  459. <entry><code>array</code></entry>
  460. <entry><code></code></entry>
  461. <entry>
  462. an array of complete path of master files
  463. </entry>
  464. </row>
  465. <row>
  466. <entry><code>master_files_mode</code></entry>
  467. <entry><code>string</code></entry>
  468. <entry><classname>Zend_Cache_Frontend_File::MODE_OR</classname></entry>
  469. <entry>
  470. <classname>Zend_Cache_Frontend_File::MODE_AND</classname> or <classname>Zend_Cache_Frontend_File::MODE_OR</classname> ;
  471. if <code>MODE_AND</code>, then all master files have to be touched to get a cache invalidation
  472. if <code>MODE_OR</code>, then a single touched master file is enough to get a cache invalidation
  473. </entry>
  474. </row>
  475. <row>
  476. <entry><code>ignore_missing_master_files</code></entry>
  477. <entry><code>boolean</code></entry>
  478. <entry><code>false</code></entry>
  479. <entry>
  480. if true, missing master files are ignored silently (an exception is raised else)
  481. </entry>
  482. </row>
  483. </tbody>
  484. </tgroup>
  485. </table>
  486. </sect3>
  487. <sect3 id="zend.cache.frontends.file.examples">
  488. <title>Examples</title>
  489. <para>
  490. Use of this frontend is the same than of <classname>Zend_Cache_Core</classname>. There
  491. is no need of a specific example - the only thing to do is to
  492. define the <code>master_file</code> when using the factory.
  493. </para>
  494. </sect3>
  495. </sect2>
  496. <sect2 id="zend.cache.frontends.page">
  497. <title>Zend_Cache_Frontend_Page</title>
  498. <sect3 id="zend.cache.frontends.page.introduction">
  499. <title>Introduction</title>
  500. <para>
  501. <classname>Zend_Cache_Frontend_Page</classname> is like <classname>Zend_Cache_Frontend_Output</classname>
  502. but designed for a complete page. It's impossible to use <classname>Zend_Cache_Frontend_Page</classname>
  503. for caching only a single block.
  504. </para>
  505. <para>
  506. On the other hand, the "cache id" is calculated automatically with
  507. <code>$_SERVER['REQUEST_URI']</code> and (depending on options)
  508. <code>$_GET</code>, <code>$_POST</code>, <code>$_SESSION</code>, <code>$_COOKIE</code>, <code>$_FILES</code>.
  509. More over, you have only one method to call (<code>start()</code>) because the
  510. <code>end()</code> call is fully automatic when the page is ended.
  511. </para>
  512. <para>
  513. For the moment, it's not implemented but we plan to add a HTTP conditional system
  514. to save bandwidth (the system will send a HTTP 304 Not Modified if the cache is hit
  515. and if the browser has already the good version).
  516. </para>
  517. </sect3>
  518. <sect3 id="zend.cache.frontends.page.options">
  519. <title>Available Options</title>
  520. <table id="zend.cache.frontends.page.options.table">
  521. <title>Page Frontend Options</title>
  522. <tgroup cols="4">
  523. <thead>
  524. <row>
  525. <entry>Option</entry>
  526. <entry>Data Type</entry>
  527. <entry>Default Value</entry>
  528. <entry>Description</entry>
  529. </row>
  530. </thead>
  531. <tbody>
  532. <row>
  533. <entry><code>http_conditional</code></entry>
  534. <entry><code>boolean</code></entry>
  535. <entry><code>false</code></entry>
  536. <entry>
  537. use the http_conditional system (not implemented for the moment)
  538. </entry>
  539. </row>
  540. <row>
  541. <entry><code>debug_header</code></entry>
  542. <entry><code>boolean</code></entry>
  543. <entry><code>false</code></entry>
  544. <entry>
  545. if true, a debug text is added before each cached pages
  546. </entry>
  547. </row>
  548. <row>
  549. <entry><code>default_options</code></entry>
  550. <entry><code>array</code></entry>
  551. <entry><code>array(...see below...)</code></entry>
  552. <entry>
  553. an associative array of default options :
  554. <itemizedlist>
  555. <listitem>
  556. <para>
  557. <code>(boolean, true by default) cache</code> :
  558. cache is on if true
  559. </para>
  560. </listitem>
  561. <listitem>
  562. <para>
  563. <code>(boolean, false by default) cache_with_get_variables</code> :
  564. if true, cache is still on even if there are some variables in
  565. <code>$_GET</code> array
  566. </para>
  567. </listitem>
  568. <listitem>
  569. <para>
  570. <code>(boolean, false by default) cache_with_post_variables</code> :
  571. if true, cache is still on even if there are some variables in
  572. <code>$_POST</code> array
  573. </para>
  574. </listitem>
  575. <listitem>
  576. <para>
  577. <code>(boolean, false by default) cache_with_session_variables</code> :
  578. if true, cache is still on even if there are some variables in
  579. <code>$_SESSION</code> array
  580. </para>
  581. </listitem>
  582. <listitem>
  583. <para>
  584. <code>(boolean, false by default) cache_with_files_variables</code> :
  585. if true, cache is still on even if there are some variables in
  586. <code>$_FILES</code> array
  587. </para>
  588. </listitem>
  589. <listitem>
  590. <para>
  591. <code>(boolean, false by default) cache_with_cookie_variables</code> :
  592. if true, cache is still on even if there are some variables in
  593. <code>$_COOKIE</code> array
  594. </para>
  595. </listitem>
  596. <listitem>
  597. <para>
  598. <code>(boolean, true by default) make_id_with_get_variables</code> :
  599. if true, the cache id will be dependent of the content of the
  600. <code>$_GET</code> array
  601. </para>
  602. </listitem>
  603. <listitem>
  604. <para>
  605. <code>(boolean, true by default) make_id_with_post_variables</code> :
  606. if true, the cache id will be dependent of the content of the
  607. <code>$_POST</code> array
  608. </para>
  609. </listitem>
  610. <listitem>
  611. <para>
  612. <code>(boolean, true by default) make_id_with_session_variables</code> :
  613. if true, the cache id will be dependent of the content of the
  614. <code>$_SESSION</code> array
  615. </para>
  616. </listitem>
  617. <listitem>
  618. <para>
  619. <code>(boolean, true by default) make_id_with_files_variables</code> :
  620. if true, the cache id will be dependent of the content of the
  621. <code>$_FILES</code> array
  622. </para>
  623. </listitem>
  624. <listitem>
  625. <para>
  626. <code>(boolean, true by default) make_id_with_cookie_variables</code> :
  627. if true, the cache id will be dependent of the content of the
  628. <code>$_COOKIE</code> array
  629. </para>
  630. </listitem>
  631. <listitem>
  632. <para>
  633. <code>(int, false by default) specific_lifetime</code> :
  634. if not false, the given lifetime will be used for the choosen regexp
  635. </para>
  636. </listitem>
  637. <listitem>
  638. <para>
  639. <code>(array, array() by default) tags</code> :
  640. tags for the cache record
  641. </para>
  642. </listitem>
  643. <listitem>
  644. <para>
  645. <code>(int, null by default) priority</code> :
  646. priority (if the backend supports it)
  647. </para>
  648. </listitem>
  649. </itemizedlist>
  650. </entry>
  651. </row>
  652. <row>
  653. <entry><code>regexps</code></entry>
  654. <entry><code>array</code></entry>
  655. <entry><code>array()</code></entry>
  656. <entry>
  657. an associative array to set options only for some REQUEST_URI, keys are (PCRE) regexps, values are
  658. associative arrays with specific options to set if the regexp matchs on $_SERVER['REQUEST_URI']
  659. (see default_options for the list of available options) ; if several regexps match the $_SERVER['REQUEST_URI'],
  660. only the last one will be used
  661. </entry>
  662. </row>
  663. <row>
  664. <entry><code>memorize_headers</code></entry>
  665. <entry><code>array</code></entry>
  666. <entry><code>array()</code></entry>
  667. <entry>
  668. an array of strings corresponding to some HTTP headers name. Listed headers
  669. will be stored with cache datas and "replayed" when the cache is hit
  670. </entry>
  671. </row>
  672. </tbody>
  673. </tgroup>
  674. </table>
  675. </sect3>
  676. <sect3 id="zend.cache.frontends.page.examples">
  677. <title>Examples</title>
  678. <para>
  679. Use of <classname>Zend_Cache_Frontend_Page</classname> is really trivial:
  680. </para>
  681. <programlisting role="php"><![CDATA[
  682. // [...] // require, configuration and factory
  683. $cache->start();
  684. // if the cache is hit, the result is sent to the browser
  685. // and the script stop here
  686. // rest of the page ...
  687. ]]></programlisting>
  688. <para>
  689. a more complex example which shows a way to get a centralized cache management in a bootstrap file
  690. (for using with <classname>Zend_Controller</classname> for example)
  691. </para>
  692. <programlisting role="php"><![CDATA[
  693. /*
  694. * You should avoid putting too many lines before the cache section.
  695. * For example, for optimal performances, "require_once" or
  696. * "Zend_Loader::loadClass" should be after the cache section.
  697. */
  698. $frontendOptions = array(
  699. 'lifetime' => 7200,
  700. 'debug_header' => true, // for debugging
  701. 'regexps' => array(
  702. // cache the whole IndexController
  703. '^/$' => array('cache' => true),
  704. // cache the whole IndexController
  705. '^/index/' => array('cache' => true),
  706. // we don't cache the ArticleController...
  707. '^/article/' => array('cache' => false),
  708. // ... but we cache the "view" action of this ArticleController
  709. '^/article/view/' => array(
  710. 'cache' => true,
  711. // and we cache even there are some variables in $_POST
  712. 'cache_with_post_variables' => true,
  713. // but the cache will be dependent on the $_POST array
  714. 'make_id_with_post_variables' => true
  715. )
  716. )
  717. );
  718. $backendOptions = array(
  719. 'cache_dir' => '/tmp/'
  720. );
  721. // getting a Zend_Cache_Frontend_Page object
  722. $cache = Zend_Cache::factory('Page',
  723. 'File',
  724. $frontendOptions,
  725. $backendOptions);
  726. $cache->start();
  727. // if the cache is hit, the result is sent to the browser and the
  728. // script stop here
  729. // [...] the end of the bootstrap file
  730. // these lines won't be executed if the cache is hit
  731. ]]></programlisting>
  732. </sect3>
  733. <sect3 id="zend.cache.frontends.page.cancel">
  734. <title>The Specific Cancel Method</title>
  735. <para>
  736. Because of design issues, in some cases (for example when using non HTTP/200 return codes),
  737. you could need to cancel the current cache process. So we introduce for this
  738. particular frontend, the cancel() method.
  739. </para>
  740. <programlisting role="php"><![CDATA[
  741. // [...] // require, configuration and factory
  742. $cache->start();
  743. // [...]
  744. if ($someTest) {
  745. $cache->cancel();
  746. // [...]
  747. }
  748. // [...]
  749. ]]></programlisting>
  750. </sect3>
  751. </sect2>
  752. </sect1>
  753. <!--
  754. vim:se ts=4 sw=4 et:
  755. -->