Zend_Cache-Frontends.xml 38 KB

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