Zend_Cache-Backends.xml 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.cache.backends">
  4. <title>Zend_Cache Backends</title>
  5. <para>
  6. There are two kinds of backends: standard ones and extended ones. Of course, extended
  7. backends offer more features.
  8. </para>
  9. <sect2 id="zend.cache.backends.file">
  10. <title>Zend_Cache_Backend_File</title>
  11. <para>
  12. This (extended) backends stores cache records into files (in a chosen directory).
  13. </para>
  14. <para>
  15. Available options are :
  16. </para>
  17. <table id="zend.cache.backends.file.table">
  18. <title>File Backend Options</title>
  19. <tgroup cols="4">
  20. <thead>
  21. <row>
  22. <entry>Option</entry>
  23. <entry>Data Type</entry>
  24. <entry>Default Value</entry>
  25. <entry>Description</entry>
  26. </row>
  27. </thead>
  28. <tbody>
  29. <row>
  30. <entry><emphasis>cache_dir</emphasis></entry>
  31. <entry><type>String</type></entry>
  32. <entry>[system temp dir]</entry>
  33. <entry>Directory where to store cache files</entry>
  34. </row>
  35. <row>
  36. <entry><emphasis>file_locking</emphasis></entry>
  37. <entry><type>Boolean</type></entry>
  38. <entry><constant>TRUE</constant></entry>
  39. <entry>
  40. Enable or disable file_locking : Can avoid cache corruption under
  41. bad circumstances but it doesn't help on multithread webservers
  42. or on <acronym>NFS</acronym> filesystems...
  43. </entry>
  44. </row>
  45. <row>
  46. <entry><emphasis>read_control</emphasis></entry>
  47. <entry><type>Boolean</type></entry>
  48. <entry><constant>TRUE</constant></entry>
  49. <entry>
  50. Enable / disable read control : if enabled, a control key is
  51. embedded in the cache file and this key is compared with the
  52. one calculated after the reading.
  53. </entry>
  54. </row>
  55. <row>
  56. <entry><emphasis>read_control_type</emphasis></entry>
  57. <entry><type>String</type></entry>
  58. <entry>'crc32'</entry>
  59. <entry>
  60. Type of read control (only if read control is enabled). Available values
  61. are : 'md5' (best but slowest), 'crc32' (lightly less safe but faster,
  62. better choice), 'adler32' (new choice, faster than crc32),
  63. 'strlen' for a length only test (fastest).
  64. </entry>
  65. </row>
  66. <row>
  67. <entry><emphasis>hashed_directory_level</emphasis></entry>
  68. <entry><type>Integer</type></entry>
  69. <entry>0</entry>
  70. <entry>
  71. Hashed directory structure level : 0 means "no hashed directory
  72. structure", 1 means "one level of directory", 2 means "two levels"...
  73. This option can speed up the cache only when you have many thousands of
  74. cache files. Only specific benchs can help you to choose the perfect
  75. value for you. Maybe, 1 or 2 is a good start.
  76. </entry>
  77. </row>
  78. <row>
  79. <entry><emphasis>hashed_directory_umask</emphasis></entry>
  80. <entry><type>Integer</type></entry>
  81. <entry>0700</entry>
  82. <entry>Umask for the hashed directory structure</entry>
  83. </row>
  84. <row>
  85. <entry><emphasis>file_name_prefix</emphasis></entry>
  86. <entry><type>String</type></entry>
  87. <entry>'zend_cache'</entry>
  88. <entry>
  89. prefix for cache files ; be really careful with this option because
  90. a too generic value in a system cache dir
  91. (like <filename>/tmp</filename>) can cause disasters when cleaning
  92. the cache
  93. </entry>
  94. </row>
  95. <row>
  96. <entry><emphasis>cache_file_umask</emphasis></entry>
  97. <entry><type>Integer</type></entry>
  98. <entry>0600</entry>
  99. <entry>umask for cache files</entry>
  100. </row>
  101. <row>
  102. <entry><emphasis>metatadatas_array_max_size</emphasis></entry>
  103. <entry><type>Integer</type></entry>
  104. <entry>100</entry>
  105. <entry>
  106. internal max size for the metadatas array (don't change this value
  107. unless you know what you are doing)
  108. </entry>
  109. </row>
  110. </tbody>
  111. </tgroup>
  112. </table>
  113. </sect2>
  114. <sect2 id="zend.cache.backends.sqlite">
  115. <title>Zend_Cache_Backend_Sqlite</title>
  116. <para>
  117. This (extended) backends stores cache records into a SQLite database.
  118. </para>
  119. <para>
  120. Available options are :
  121. </para>
  122. <table id="zend.cache.backends.sqlite.table">
  123. <title>Sqlite Backend Options</title>
  124. <tgroup cols="4">
  125. <thead>
  126. <row>
  127. <entry>Option</entry>
  128. <entry>Data Type</entry>
  129. <entry>Default Value</entry>
  130. <entry>Description</entry>
  131. </row>
  132. </thead>
  133. <tbody>
  134. <row>
  135. <entry><emphasis>cache_db_complete_path (mandatory)</emphasis></entry>
  136. <entry><type>String</type></entry>
  137. <entry><constant>NULL</constant></entry>
  138. <entry>
  139. The complete path (filename included) of the SQLite database
  140. </entry>
  141. </row>
  142. <row>
  143. <entry><emphasis>automatic_vacuum_factor</emphasis></entry>
  144. <entry><type>Integer</type></entry>
  145. <entry>10</entry>
  146. <entry>
  147. Disable / Tune the automatic vacuum process. The automatic vacuum
  148. process defragment the database file (and make it smaller) when a
  149. <methodname>clean()</methodname> or <methodname>delete()</methodname>
  150. is called: 0 means no automatic vacuum ; 1 means systematic vacuum
  151. (when <methodname>delete()</methodname> or
  152. <methodname>clean()</methodname> methods are called) ; x (integer) >
  153. 1 => automatic vacuum randomly 1 times on x
  154. <methodname>clean()</methodname> or
  155. <methodname>delete()</methodname>.
  156. </entry>
  157. </row>
  158. </tbody>
  159. </tgroup>
  160. </table>
  161. </sect2>
  162. <sect2 id="zend.cache.backends.memcached">
  163. <title>Zend_Cache_Backend_Memcached</title>
  164. <para>
  165. This (extended) backends stores cache records into a memcached server. <ulink
  166. url="http://www.danga.com/memcached/">memcached</ulink> is a high-performance,
  167. distributed memory object caching system. To use this backend, you need a memcached
  168. daemon and <ulink url="http://pecl.php.net/package/memcache">the memcache
  169. <acronym>PECL</acronym> extension</ulink>.
  170. </para>
  171. <para>
  172. Be careful : with this backend, "tags" are not supported for the moment as
  173. the "doNotTestCacheValidity=true" argument.
  174. </para>
  175. <para>
  176. Available options are :
  177. </para>
  178. <table id="zend.cache.backends.memcached.table">
  179. <title>Memcached Backend Options</title>
  180. <tgroup cols="4">
  181. <thead>
  182. <row>
  183. <entry>Option</entry>
  184. <entry>Data Type</entry>
  185. <entry>Default Value</entry>
  186. <entry>Description</entry>
  187. </row>
  188. </thead>
  189. <tbody>
  190. <row>
  191. <entry><emphasis>servers</emphasis></entry>
  192. <entry><type>Array</type></entry>
  193. <entry>
  194. <command>array(array('host' => 'localhost', 'port' => 11211,
  195. 'persistent' => true, 'weight' => 1, 'timeout' => 5,
  196. 'retry_interval' => 15, 'status' => true,
  197. 'failure_callback' => '' ))</command>
  198. </entry>
  199. <entry>
  200. An array of memcached servers ; each memcached server is described by
  201. an associative array : 'host' => (string) : the name of the memcached
  202. server, 'port' => (int) : the port of the memcached server,
  203. 'persistent' => (bool) : use or not persistent connections to this
  204. memcached server 'weight' => (int) :the weight of the memcached
  205. server, 'timeout' => (int) :the time out of the memcached server,
  206. 'retry_interval' => (int) :the retry interval of the memcached server,
  207. 'status' => (bool) :the status of the memcached server,
  208. 'failure_callback' => (callback) : the failure_callback of the
  209. memcached server
  210. </entry>
  211. </row>
  212. <row>
  213. <entry><emphasis>compression</emphasis></entry>
  214. <entry><type>Boolean</type></entry>
  215. <entry><constant>FALSE</constant></entry>
  216. <entry>
  217. <constant>TRUE</constant> if you want to use on-the-fly compression
  218. </entry>
  219. </row>
  220. <row>
  221. <entry><emphasis>compatibility</emphasis></entry>
  222. <entry><type>Boolean</type></entry>
  223. <entry><constant>FALSE</constant></entry>
  224. <entry>
  225. <constant>TRUE</constant> if you want to use this compatibility mode
  226. with old memcache servers or extensions
  227. </entry>
  228. </row>
  229. </tbody>
  230. </tgroup>
  231. </table>
  232. </sect2>
  233. <sect2 id="zend.cache.backends.libmemcached">
  234. <title>Zend_Cache_Backend_Libmemcached</title>
  235. <para>
  236. This (extended) backend stores cache records into a memcached server. <ulink
  237. url="http://www.danga.com/memcached/">memcached</ulink> is a high-performance,
  238. distributed memory object caching system. To use this backend, you need a memcached
  239. daemon and <ulink url="http://pecl.php.net/package/memcached">the memcached
  240. <acronym>PECL</acronym> extension</ulink>.
  241. </para>
  242. <para>
  243. Be careful : with this backend, "tags" are not supported for the moment as
  244. the "doNotTestCacheValidity=true" argument.
  245. </para>
  246. <para>
  247. Available options are :
  248. </para>
  249. <table id="zend.cache.backends.libmemcached.table">
  250. <title>Libmemcached Backend Options</title>
  251. <tgroup cols="4">
  252. <thead>
  253. <row>
  254. <entry>Option</entry>
  255. <entry>Data Type</entry>
  256. <entry>Default Value</entry>
  257. <entry>Description</entry>
  258. </row>
  259. </thead>
  260. <tbody>
  261. <row>
  262. <entry><emphasis>servers</emphasis></entry>
  263. <entry><type>Array</type></entry>
  264. <entry>
  265. <command>array(array('host' => 'localhost', 'port' => 11211,
  266. 'weight' => 1))</command>
  267. </entry>
  268. <entry>
  269. An array of memcached servers ; each memcached server is described by
  270. an associative array:
  271. 'host' => (string) : the name of the memcached server,
  272. 'port' => (int) : the port of the memcached server,
  273. 'weight' => (int) :the weight of the memcached server
  274. </entry>
  275. </row>
  276. <row>
  277. <entry><emphasis>client</emphasis></entry>
  278. <entry><type>Array</type></entry>
  279. <entry>
  280. <command>array(
  281. Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
  282. Memcached::OPT_HASH => Memcached::HASH_MD5,
  283. Memcached::OPT_LIBKETAMA_COMPATIBLE => true
  284. )</command>
  285. </entry>
  286. <entry>
  287. An associative array of memcached client options ;
  288. The array key can be the name of the memcached option constant
  289. (without 'OPT_') or the integer value of it.
  290. See <ulink url="http://php.net/manual/memcached.constants.php">
  291. Memcached constants on <acronym>PHP</acronym> manual</ulink>
  292. </entry>
  293. </row>
  294. </tbody>
  295. </tgroup>
  296. </table>
  297. </sect2>
  298. <sect2 id="zend.cache.backends.apc">
  299. <title>Zend_Cache_Backend_Apc</title>
  300. <para>
  301. This (extended) backends stores cache records in shared memory through
  302. the <ulink url="http://pecl.php.net/package/APC">APC</ulink> (Alternative
  303. <acronym>PHP</acronym> Cache) extension (which is of course need for using this
  304. backend).
  305. </para>
  306. <para>
  307. Be careful : with this backend, "tags" are not supported for the moment as
  308. the "doNotTestCacheValidity=true" argument.
  309. </para>
  310. <para>
  311. There is no option for this backend.
  312. </para>
  313. </sect2>
  314. <sect2 id="zend.cache.backends.xcache">
  315. <title>Zend_Cache_Backend_Xcache</title>
  316. <para>
  317. This backends stores cache records in shared memory through
  318. the <ulink url="http://xcache.lighttpd.net/">XCache</ulink> extension
  319. (which is of course need for using this backend).
  320. </para>
  321. <para>
  322. Be careful : with this backend, "tags" are not supported for the moment as
  323. the "doNotTestCacheValidity=true" argument.
  324. </para>
  325. <para>
  326. Available options are :
  327. </para>
  328. <table id="zend.cache.backends.xcache.table">
  329. <title>Xcache Backend Options</title>
  330. <tgroup cols="4">
  331. <thead>
  332. <row>
  333. <entry>Option</entry>
  334. <entry>Data Type</entry>
  335. <entry>Default Value</entry>
  336. <entry>Description</entry>
  337. </row>
  338. </thead>
  339. <tbody>
  340. <row>
  341. <entry><emphasis>user</emphasis></entry>
  342. <entry><type>String</type></entry>
  343. <entry><constant>NULL</constant></entry>
  344. <entry>
  345. <filename>xcache.admin.user</filename>, necessary for the
  346. <methodname>clean()</methodname> method
  347. </entry>
  348. </row>
  349. <row>
  350. <entry><emphasis>password</emphasis></entry>
  351. <entry><type>String</type></entry>
  352. <entry><constant>NULL</constant></entry>
  353. <entry>
  354. <filename>xcache.admin.pass</filename> (in clear form, not
  355. <acronym>MD5</acronym>), necessary for the
  356. <methodname>clean()</methodname> method
  357. </entry>
  358. </row>
  359. </tbody>
  360. </tgroup>
  361. </table>
  362. </sect2>
  363. <sect2 id="zend.cache.backends.platform">
  364. <title>Zend_Cache_Backend_ZendPlatform</title>
  365. <para>
  366. This backend uses content caching <acronym>API</acronym> of the <ulink
  367. url="http://www.zend.com/en/products/platform/">Zend Platform</ulink> product.
  368. Naturally, to use this backend you need to have Zend Platform installed.
  369. </para>
  370. <para>
  371. This backend supports tags, but does not support
  372. <constant>CLEANING_MODE_NOT_MATCHING_TAG</constant> cleaning mode.
  373. </para>
  374. <para>
  375. Specify this backend using a word separator -- '-', '.', ' ', or '_'
  376. -- between the words 'Zend' and 'Platform' when using the
  377. <methodname>Zend_Cache::factory()</methodname> method:
  378. </para>
  379. <programlisting language="php"><![CDATA[
  380. $cache = Zend_Cache::factory('Core', 'Zend Platform');
  381. ]]></programlisting>
  382. <para>
  383. There are no options for this backend.
  384. </para>
  385. </sect2>
  386. <sect2 id="zend.cache.backends.twolevels">
  387. <title>Zend_Cache_Backend_TwoLevels</title>
  388. <para>
  389. This (extend) backend is an hybrid one. It stores cache records in two other backends :
  390. a fast one (but limited) like Apc, Memcache... and a "slow" one like File, Sqlite...
  391. </para>
  392. <para>
  393. This backend will use the priority parameter (given at the frontend level when storing a
  394. record) and the remaining space in the fast backend to optimize the usage of these two
  395. backends.
  396. </para>
  397. <para>
  398. Specify this backend using a word separator -- '-', '.', ' ', or '_'
  399. -- between the words 'Two' and 'Levels' when using the
  400. <methodname>Zend_Cache::factory()</methodname> method:
  401. </para>
  402. <programlisting language="php"><![CDATA[
  403. $cache = Zend_Cache::factory('Core', 'Two Levels');
  404. ]]></programlisting>
  405. <para>
  406. Available options are :
  407. </para>
  408. <table id="zend.cache.backends.twolevels.table">
  409. <title>TwoLevels Backend Options</title>
  410. <tgroup cols="4">
  411. <thead>
  412. <row>
  413. <entry>Option</entry>
  414. <entry>Data Type</entry>
  415. <entry>Default Value</entry>
  416. <entry>Description</entry>
  417. </row>
  418. </thead>
  419. <tbody>
  420. <row>
  421. <entry><emphasis>slow_backend</emphasis></entry>
  422. <entry><type>String</type></entry>
  423. <entry>File</entry>
  424. <entry>the "slow" backend name</entry>
  425. </row>
  426. <row>
  427. <entry><emphasis>fast_backend</emphasis></entry>
  428. <entry><type>String</type></entry>
  429. <entry>Apc</entry>
  430. <entry>the "fast" backend name</entry>
  431. </row>
  432. <row>
  433. <entry><emphasis>slow_backend_options</emphasis></entry>
  434. <entry><type>Array</type></entry>
  435. <entry><methodname>array()</methodname></entry>
  436. <entry>the "slow" backend options</entry>
  437. </row>
  438. <row>
  439. <entry><emphasis>fast_backend_options</emphasis></entry>
  440. <entry><type>Array</type></entry>
  441. <entry><methodname>array()</methodname></entry>
  442. <entry>the "fast" backend options</entry>
  443. </row>
  444. <row>
  445. <entry><emphasis>slow_backend_custom_naming</emphasis></entry>
  446. <entry><type>Boolean</type></entry>
  447. <entry><constant>FALSE</constant></entry>
  448. <entry>
  449. if <constant>TRUE</constant>, the slow_backend argument is used as a
  450. complete class name; if <constant>FALSE</constant>,
  451. the frontend argument is used as the end of
  452. "<classname>Zend_Cache_Backend_</classname>[...]" class name
  453. </entry>
  454. </row>
  455. <row>
  456. <entry><emphasis>fast_backend_custom_naming</emphasis></entry>
  457. <entry><type>Boolean</type></entry>
  458. <entry><constant>FALSE</constant></entry>
  459. <entry>
  460. if <constant>TRUE</constant>, the fast_backend argument is used as a
  461. complete class name; if <constant>FALSE</constant>,
  462. the frontend argument is used as the end of
  463. "<classname>Zend_Cache_Backend_</classname>[...]" class name
  464. </entry>
  465. </row>
  466. <row>
  467. <entry><emphasis>slow_backend_autoload</emphasis></entry>
  468. <entry><type>Boolean</type></entry>
  469. <entry><constant>FALSE</constant></entry>
  470. <entry>
  471. if <constant>TRUE</constant>, there will no require_once for the
  472. slow backend (useful only for custom backends)
  473. </entry>
  474. </row>
  475. <row>
  476. <entry><emphasis>fast_backend_autoload</emphasis></entry>
  477. <entry><type>Boolean</type></entry>
  478. <entry><constant>FALSE</constant></entry>
  479. <entry>
  480. if <constant>TRUE</constant>, there will no require_once for the fast
  481. backend (useful only for custom backends)
  482. </entry>
  483. </row>
  484. <row>
  485. <entry><emphasis>auto_refresh_fast_cache</emphasis></entry>
  486. <entry><type>Boolean</type></entry>
  487. <entry><constant>TRUE</constant></entry>
  488. <entry>
  489. if <constant>TRUE</constant>, auto refresh the fast cache when a
  490. cache record is hit
  491. </entry>
  492. </row>
  493. <row>
  494. <entry><emphasis>stats_update_factor</emphasis></entry>
  495. <entry><type>Integer</type></entry>
  496. <entry>10</entry>
  497. <entry>
  498. disable / tune the computation of the fast backend filling percentage
  499. (when saving a record into cache, computation of the fast backend
  500. filling percentage randomly 1 times on x cache writes)
  501. </entry>
  502. </row>
  503. </tbody>
  504. </tgroup>
  505. </table>
  506. </sect2>
  507. <sect2 id="zend.cache.backends.zendserver">
  508. <title>Zend_Cache_Backend_ZendServer_Disk and Zend_Cache_Backend_ZendServer_ShMem</title>
  509. <para>
  510. These backends store cache records using <ulink
  511. url="http://www.zend.com/en/products/server/downloads-all?zfs=zf_download">Zend
  512. Server</ulink> caching functionality.
  513. </para>
  514. <para>
  515. Be careful: with these backends, "tags" are not supported for the moment as the
  516. "doNotTestCacheValidity=true" argument.
  517. </para>
  518. <para>
  519. These backend work only withing Zend Server environment for pages requested through
  520. <acronym>HTTP</acronym> or <acronym>HTTPS</acronym> and don't work for command line
  521. script execution
  522. </para>
  523. <para>
  524. Specify this backend using parameter <emphasis>customBackendNaming</emphasis> as
  525. <constant>TRUE</constant> when using the <methodname>Zend_Cache::factory()</methodname>
  526. method:
  527. </para>
  528. <programlisting language="php"><![CDATA[
  529. $cache = Zend_Cache::factory('Core', 'Zend_Cache_Backend_ZendServer_Disk',
  530. $frontendOptions, $backendOptions, false, true);
  531. ]]></programlisting>
  532. <para>
  533. There is no option for this backend.
  534. </para>
  535. </sect2>
  536. <sect2 id="zend.cache.backends.static">
  537. <title>Zend_Cache_Backend_Static</title>
  538. <para>
  539. This backend works in concert with <classname>Zend_Cache_Frontend_Capture</classname>
  540. (the two must be used together) to save the output from requests as static files. This
  541. means the static files are served directly on subsequent requests without any
  542. involvement of <acronym>PHP</acronym> or Zend Framework at all.
  543. </para>
  544. <note>
  545. <para>
  546. <classname>Zend_Cache_Frontend_Capture</classname> operates
  547. by registering a callback function to be called
  548. when the output buffering it uses is cleaned. In order for this to operate
  549. correctly, it must be the final output buffer in the request. To guarantee
  550. this, the output buffering used by the Dispatcher <emphasis>must</emphasis> be
  551. disabled by calling <classname>Zend_Controller_Front</classname>'s
  552. <methodname>setParam()</methodname> method, for example,
  553. <command>$front->setParam('disableOutputBuffering', true);</command> or adding
  554. "resources.frontcontroller.params.disableOutputBuffering = true"
  555. to your bootstrap configuration file (assumed <acronym>INI</acronym>) if using
  556. <classname>Zend_Application</classname>.
  557. </para>
  558. </note>
  559. <para>
  560. The benefits of this cache include a large throughput increase since
  561. all subsequent requests return the static file and don't need any
  562. dynamic processing. Of course this also has some disadvantages. The
  563. only way to retry the dynamic request is to purge the cached file
  564. from elsewhere in the application (or via a cronjob if timed). It
  565. is also restricted to single-server applications where only one
  566. filesystem is used. Nevertheless, it can be a powerful means of
  567. getting more performance without incurring the cost of a proxy on
  568. single machines.
  569. </para>
  570. <para>
  571. Before describing its options, you should note this needs some
  572. changes to the default <filename>.htaccess</filename> file in order for requests to be
  573. directed to the static files if they exist. Here's an example of
  574. a simple application caching some content, including two specific
  575. feeds which need additional treatment to serve a correct
  576. Content-Type header:
  577. </para>
  578. <programlisting language="text"><![CDATA[
  579. AddType application/rss+xml .xml
  580. AddType application/atom+xml .xml
  581. RewriteEngine On
  582. RewriteCond %{REQUEST_URI} feed/rss$
  583. RewriteCond %{DOCUMENT_ROOT}/cached/%{REQUEST_URI}.xml -f
  584. RewriteRule .* cached/%{REQUEST_URI}.xml [L,T=application/rss+xml]
  585. RewriteCond %{REQUEST_URI} feed/atom$
  586. RewriteCond %{DOCUMENT_ROOT}/cached/%{REQUEST_URI}.xml -f
  587. RewriteRule .* cached/%{REQUEST_URI}.xml [L,T=application/atom+xml]
  588. RewriteCond %{DOCUMENT_ROOT}/cached/index.html -f
  589. RewriteRule ^/*$ cached/index.html [L]
  590. RewriteCond %{DOCUMENT_ROOT}/cached/%{REQUEST_URI}.(html|xml|json|opml|svg) -f
  591. RewriteRule .* cached/%{REQUEST_URI}.%1 [L]
  592. RewriteCond %{REQUEST_FILENAME} -s [OR]
  593. RewriteCond %{REQUEST_FILENAME} -l [OR]
  594. RewriteCond %{REQUEST_FILENAME} -d
  595. RewriteRule ^.*$ - [NC,L]
  596. RewriteRule ^.*$ index.php [NC,L]
  597. ]]></programlisting>
  598. <para>
  599. The above assumes static files are cached to the directory
  600. <filename>./public/cached</filename>. We'll cover the option setting this location,
  601. "public_dir", below.
  602. </para>
  603. <para>
  604. Due to the nature of static file caching, the backend class offers two additional
  605. methods: <methodname>remove()</methodname> and
  606. <methodname>removeRecursively()</methodname>. Both accept a request
  607. <acronym>URI</acronym>, which when mapped to the "public_dir" where static files are
  608. cached, and has a pre-stored extension appended, provides the name of either a static
  609. file to delete, or a directory path to delete recursively. Due to the
  610. restraints of <classname>Zend_Cache_Backend_Interface</classname>, all
  611. other methods such as <methodname>save()</methodname> accept an ID which
  612. is calculated by applying <methodname>bin2hex()</methodname> to a request
  613. <acronym>URI</acronym>.
  614. </para>
  615. <para>
  616. Given the level at which static caching operates, static file caching is addressed for
  617. simpler use with the <classname>Zend_Controller_Action_Helper_Cache</classname> action
  618. helper. This helper assists in setting which actions of a controller to cache, with what
  619. tags, and with which extension. It also offers methods for purging the cache by request
  620. <acronym>URI</acronym> or tag. Static file caching is also assisted by
  621. <classname>Zend_Cache_Manager</classname> which includes pre-configured configuration
  622. templates for a static cache (as <constant>Zend_Cache_Manager::PAGECACHE</constant> or
  623. "page"). The defaults therein can be configured as needed to set up a "public_dir"
  624. location for caching, etc.
  625. </para>
  626. <note>
  627. <para>
  628. It should be noted that the static cache actually uses a secondary cache to store
  629. tags (obviously we can't store them elsewhere since a static cache does not invoke
  630. <acronym>PHP</acronym> if working correctly). This is just a standard Core cache,
  631. and should use a persistent backend such as File or TwoLevels (to take advantage of
  632. memory storage without sacrificing permanent persistance). The backend includes the
  633. option "tag_cache" to set this up (it is obligatory), or the
  634. <methodname>setInnerCache()</methodname> method.
  635. </para>
  636. </note>
  637. <table id="zend.cache.backends.static.table">
  638. <title>Static Backend Options</title>
  639. <tgroup cols="4">
  640. <thead>
  641. <row>
  642. <entry>Option</entry>
  643. <entry>Data Type</entry>
  644. <entry>Default Value</entry>
  645. <entry>Description</entry>
  646. </row>
  647. </thead>
  648. <tbody>
  649. <row>
  650. <entry><emphasis>public_dir</emphasis></entry>
  651. <entry><type>String</type></entry>
  652. <entry><constant>NULL</constant></entry>
  653. <entry>
  654. Directory where to store static files. This must exist
  655. in your public directory.
  656. </entry>
  657. </row>
  658. <row>
  659. <entry><emphasis>file_locking</emphasis></entry>
  660. <entry><type>Boolean</type></entry>
  661. <entry><constant>TRUE</constant></entry>
  662. <entry>
  663. Enable or disable file_locking : Can avoid cache corruption under
  664. bad circumstances but it doesn't help on multithread webservers
  665. or on <acronym>NFS</acronym> filesystems...
  666. </entry>
  667. </row>
  668. <row>
  669. <entry><emphasis>read_control</emphasis></entry>
  670. <entry><type>Boolean</type></entry>
  671. <entry><constant>TRUE</constant></entry>
  672. <entry>
  673. Enable / disable read control : if enabled, a control key is
  674. embedded in the cache file and this key is compared with the
  675. one calculated after the reading.
  676. </entry>
  677. </row>
  678. <row>
  679. <entry><emphasis>read_control_type</emphasis></entry>
  680. <entry><type>String</type></entry>
  681. <entry>'crc32'</entry>
  682. <entry>
  683. Type of read control (only if read control is enabled). Available values
  684. are : 'md5' (best but slowest), 'crc32' (lightly less safe but faster,
  685. better choice), 'adler32' (new choice, faster than crc32),
  686. 'strlen' for a length only test (fastest).
  687. </entry>
  688. </row>
  689. <row>
  690. <entry><emphasis>cache_file_umask</emphasis></entry>
  691. <entry><type>Integer</type></entry>
  692. <entry>0600</entry>
  693. <entry>umask for cached files.</entry>
  694. </row>
  695. <row>
  696. <entry><emphasis>cache_directory_umask</emphasis></entry>
  697. <entry><type>Integer</type></entry>
  698. <entry>0700</entry>
  699. <entry>Umask for directories created within public_dir.</entry>
  700. </row>
  701. <row>
  702. <entry><emphasis>file_extension</emphasis></entry>
  703. <entry><type>String</type></entry>
  704. <entry>'<filename>.html</filename>'</entry>
  705. <entry>
  706. Default file extension for static files created. This can be
  707. configured on the fly, see
  708. <methodname>Zend_Cache_Backend_Static::save()</methodname> though
  709. generally it's recommended to rely on
  710. <classname>Zend_Controller_Action_Helper_Cache</classname> when
  711. doing so since it's simpler that way than messing with
  712. arrays or serialization manually.
  713. </entry>
  714. </row>
  715. <row>
  716. <entry><emphasis>index_filename</emphasis></entry>
  717. <entry><type>String</type></entry>
  718. <entry>'index'</entry>
  719. <entry>
  720. If a request <acronym>URI</acronym> does not contain sufficient
  721. information to construct a static file (usually this means an index
  722. call, e.g. <acronym>URI</acronym> of '/'), the index_filename is used
  723. instead. So '' or '/' would map to '<filename>index.html</filename>'
  724. (assuming the default file_extension is '<filename>.html</filename>').
  725. </entry>
  726. </row>
  727. <row>
  728. <entry><emphasis>tag_cache</emphasis></entry>
  729. <entry><type>Object</type></entry>
  730. <entry><constant>NULL</constant></entry>
  731. <entry>
  732. Used to set an 'inner' cache utilised to store tags
  733. and file extensions associated with static files. This
  734. <emphasis>must</emphasis> be set or the static cache cannot be tracked
  735. and managed.
  736. </entry>
  737. </row>
  738. <row>
  739. <entry><emphasis>disable_caching</emphasis></entry>
  740. <entry><type>Boolean</type></entry>
  741. <entry><constant>FALSE</constant></entry>
  742. <entry>
  743. If set to <constant>TRUE</constant>, static files will not be cached.
  744. This will force all requests to be dynamic even if marked
  745. to be cached in Controllers. Useful for debugging.
  746. </entry>
  747. </row>
  748. </tbody>
  749. </tgroup>
  750. </table>
  751. </sect2>
  752. </sect1>
  753. <!--
  754. vim:se ts=4 sw=4 et:
  755. -->