Zend_Cache-Frontends.xml 41 KB

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