Zend_Cache-Frontends.xml 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  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. </sect3>
  541. <sect3 id="zend.cache.frontends.page.options">
  542. <title>Available Options</title>
  543. <table id="zend.cache.frontends.page.options.table">
  544. <title>Page Frontend Options</title>
  545. <tgroup cols="4">
  546. <thead>
  547. <row>
  548. <entry>Option</entry>
  549. <entry>Data Type</entry>
  550. <entry>Default Value</entry>
  551. <entry>Description</entry>
  552. </row>
  553. </thead>
  554. <tbody>
  555. <row>
  556. <entry><emphasis>http_conditional</emphasis></entry>
  557. <entry><type>Boolean</type></entry>
  558. <entry><constant>FALSE</constant></entry>
  559. <entry>
  560. use the http_conditional system (not implemented for the moment)
  561. </entry>
  562. </row>
  563. <row>
  564. <entry><emphasis>debug_header</emphasis></entry>
  565. <entry><type>Boolean</type></entry>
  566. <entry><constant>FALSE</constant></entry>
  567. <entry>
  568. if <constant>TRUE</constant>, a debug text is added before each
  569. cached pages
  570. </entry>
  571. </row>
  572. <row>
  573. <entry><emphasis>default_options</emphasis></entry>
  574. <entry><type>Array</type></entry>
  575. <entry><methodname>array(...see below...)</methodname></entry>
  576. <entry>
  577. an associative array of default options:
  578. <itemizedlist>
  579. <listitem>
  580. <para>
  581. <emphasis>(boolean, <constant>TRUE</constant> by
  582. default) cache</emphasis>: cache is on if
  583. <constant>TRUE</constant>
  584. </para>
  585. </listitem>
  586. <listitem>
  587. <para>
  588. <emphasis>(boolean, <constant>FALSE</constant> by
  589. default) cache_with_get_variables</emphasis>: if
  590. <constant>TRUE</constant>,
  591. cache is still on even if there are some variables in
  592. <varname>$_GET</varname> array
  593. </para>
  594. </listitem>
  595. <listitem>
  596. <para>
  597. <emphasis>(boolean, <constant>FALSE</constant> by
  598. default) cache_with_post_variables</emphasis>: if
  599. <constant>TRUE</constant>,
  600. cache is still on even if there are some variables in
  601. <varname>$_POST</varname> array
  602. </para>
  603. </listitem>
  604. <listitem>
  605. <para>
  606. <emphasis>(boolean, <constant>FALSE</constant> by
  607. default) cache_with_session_variables</emphasis>:
  608. if <constant>TRUE</constant>,
  609. cache is still on even if there are some variables in
  610. <varname>$_SESSION</varname> array
  611. </para>
  612. </listitem>
  613. <listitem>
  614. <para>
  615. <emphasis>(boolean, <constant>FALSE</constant> by
  616. default) cache_with_files_variables</emphasis>:
  617. if <constant>TRUE</constant>,
  618. cache is still on even if there are some variables in
  619. <varname>$_FILES</varname> array
  620. </para>
  621. </listitem>
  622. <listitem>
  623. <para>
  624. <emphasis>(boolean, <constant>FALSE</constant> by
  625. default) cache_with_cookie_variables</emphasis>:
  626. if <constant>TRUE</constant>,
  627. cache is still on even if there are some variables in
  628. <varname>$_COOKIE</varname> array
  629. </para>
  630. </listitem>
  631. <listitem>
  632. <para>
  633. <emphasis>(boolean, <constant>TRUE</constant> by
  634. default) make_id_with_get_variables</emphasis>:
  635. if <constant>TRUE</constant>,
  636. the cache id will be dependent of the content of the
  637. <varname>$_GET</varname> array
  638. </para>
  639. </listitem>
  640. <listitem>
  641. <para>
  642. <emphasis>(boolean, <constant>TRUE</constant> by
  643. default) make_id_with_post_variables</emphasis>:
  644. if <constant>TRUE</constant>,
  645. the cache id will be dependent of the content of the
  646. <varname>$_POST</varname> array
  647. </para>
  648. </listitem>
  649. <listitem>
  650. <para>
  651. <emphasis>(boolean, <constant>TRUE</constant> by
  652. default)
  653. make_id_with_session_variables</emphasis>: if
  654. <constant>TRUE</constant>,
  655. the cache id will be dependent of the content of
  656. the <varname>$_SESSION</varname> array
  657. </para>
  658. </listitem>
  659. <listitem>
  660. <para>
  661. <emphasis>(boolean, <constant>TRUE</constant> by
  662. default) make_id_with_files_variables</emphasis>:
  663. if <constant>TRUE</constant>,
  664. the cache id will be dependent of the content of the
  665. <varname>$_FILES</varname> array
  666. </para>
  667. </listitem>
  668. <listitem>
  669. <para>
  670. <emphasis>(boolean, <constant>TRUE</constant> by
  671. default)
  672. make_id_with_cookie_variables</emphasis>: if
  673. <constant>TRUE</constant>,
  674. the cache id will be dependent of the content of
  675. the <varname>$_COOKIE</varname> array
  676. </para>
  677. </listitem>
  678. <listitem>
  679. <para>
  680. <emphasis>(int, <constant>FALSE</constant> by
  681. default) specific_lifetime</emphasis>: if not
  682. <constant>FALSE</constant>, the
  683. given lifetime will be used for the choosen regexp
  684. </para>
  685. </listitem>
  686. <listitem>
  687. <para>
  688. <emphasis>(array, <methodname>array()</methodname> by
  689. default) tags</emphasis>: tags for the cache
  690. record
  691. </para>
  692. </listitem>
  693. <listitem>
  694. <para>
  695. <emphasis>(int, <constant>NULL</constant> by default)
  696. priority</emphasis>: priority (if the backend
  697. supports it)
  698. </para>
  699. </listitem>
  700. </itemizedlist>
  701. </entry>
  702. </row>
  703. <row>
  704. <entry><emphasis>regexps</emphasis></entry>
  705. <entry><type>Array</type></entry>
  706. <entry><methodname>array()</methodname></entry>
  707. <entry>
  708. an associative array to set options only for some
  709. <constant>REQUEST_URI</constant>, keys are
  710. (<acronym>PCRE</acronym>) regexps, values are associative arrays
  711. with specific options to set if the regexp matchs on
  712. <varname>$_SERVER['REQUEST_URI']</varname> (see default_options
  713. for the list of available options); if several regexps match the
  714. <varname>$_SERVER['REQUEST_URI']</varname>, only the last one
  715. will be used
  716. </entry>
  717. </row>
  718. <row>
  719. <entry><emphasis>memorize_headers</emphasis></entry>
  720. <entry><type>Array</type></entry>
  721. <entry><methodname>array()</methodname></entry>
  722. <entry>
  723. an array of strings corresponding to some
  724. <acronym>HTTP</acronym> headers name. Listed headers will be
  725. stored with cache datas and "replayed" when the cache is hit
  726. </entry>
  727. </row>
  728. </tbody>
  729. </tgroup>
  730. </table>
  731. </sect3>
  732. <sect3 id="zend.cache.frontends.page.examples">
  733. <title>Examples</title>
  734. <para>
  735. Use of <classname>Zend_Cache_Frontend_Page</classname> is really trivial:
  736. </para>
  737. <programlisting language="php"><![CDATA[
  738. // [...] // require, configuration and factory
  739. $cache->start();
  740. // if the cache is hit, the result is sent to the browser
  741. // and the script stop here
  742. // rest of the page ...
  743. ]]></programlisting>
  744. <para>
  745. a more complex example which shows a way to get a centralized cache management in a
  746. bootstrap file (for using with <classname>Zend_Controller</classname> for example)
  747. </para>
  748. <programlisting language="php"><![CDATA[
  749. /*
  750. * You should avoid putting too many lines before the cache section.
  751. * For example, for optimal performances, "require_once" or
  752. * "Zend_Loader::loadClass" should be after the cache section.
  753. */
  754. $frontendOptions = array(
  755. 'lifetime' => 7200,
  756. 'debug_header' => true, // for debugging
  757. 'regexps' => array(
  758. // cache the whole IndexController
  759. '^/$' => array('cache' => true),
  760. // cache the whole IndexController
  761. '^/index/' => array('cache' => true),
  762. // we don't cache the ArticleController...
  763. '^/article/' => array('cache' => false),
  764. // ... but we cache the "view" action of this ArticleController
  765. '^/article/view/' => array(
  766. 'cache' => true,
  767. // and we cache even there are some variables in $_POST
  768. 'cache_with_post_variables' => true,
  769. // but the cache will be dependent on the $_POST array
  770. 'make_id_with_post_variables' => true
  771. )
  772. )
  773. );
  774. $backendOptions = array(
  775. 'cache_dir' => '/tmp/'
  776. );
  777. // getting a Zend_Cache_Frontend_Page object
  778. $cache = Zend_Cache::factory('Page',
  779. 'File',
  780. $frontendOptions,
  781. $backendOptions);
  782. $cache->start();
  783. // if the cache is hit, the result is sent to the browser and the
  784. // script stop here
  785. // [...] the end of the bootstrap file
  786. // these lines won't be executed if the cache is hit
  787. ]]></programlisting>
  788. </sect3>
  789. <sect3 id="zend.cache.frontends.page.cancel">
  790. <title>The Specific Cancel Method</title>
  791. <para>
  792. Because of design issues, in some cases (for example when using non
  793. <acronym>HTTP</acronym> 200 return codes), you could need to cancel the current
  794. cache process. So we introduce for this particular frontend, the
  795. <methodname>cancel()</methodname> method.
  796. </para>
  797. <programlisting language="php"><![CDATA[
  798. // [...] // require, configuration and factory
  799. $cache->start();
  800. // [...]
  801. if ($someTest) {
  802. $cache->cancel();
  803. // [...]
  804. }
  805. // [...]
  806. ]]></programlisting>
  807. </sect3>
  808. </sect2>
  809. </sect1>
  810. <!--
  811. vim:se ts=4 sw=4 et:
  812. -->