Zend_Cache-Frontends.xml 38 KB

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