Zend_Cache-Frontends.xml 42 KB

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