Zend_Cache-Backends.xml 38 KB

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