Zend_Cache-Backends.xml 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- EN-Revision: 22140 -->
  3. <!-- Reviewed: no -->
  4. <sect1 id="zend.cache.backends">
  5. <title>Les backends Zend_Cache</title>
  6. <para>
  7. Il existe deux types de backends&#160;: les standards et les étendus. Bien sûr, les
  8. backends étendus offrent des fonctionnalités supplémentaires.
  9. </para>
  10. <sect2 id="zend.cache.backends.file">
  11. <title>Zend_Cache_Backend_File</title>
  12. <para>
  13. Ces backends (étendus) stockent les enregistrements de cache dans des fichiers
  14. (dans un dossier choisi).
  15. </para>
  16. <para>Les options disponibles sont&#160;:</para>
  17. <table id="zend.cache.backends.file.table">
  18. <title>Options du backend File</title>
  19. <tgroup cols="4">
  20. <thead>
  21. <row>
  22. <entry>Option</entry>
  23. <entry>Type de données</entry>
  24. <entry>Valeur par défaut</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><filename>/tmp/</filename></entry>
  33. <entry>Répertoire où stocker les fichiers de cache</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. Active / désactive le verrou de fichier&#160;: peut éviter la
  41. corruption du cache dans de mauvaises circonstances, mais il n'aide en
  42. rien sur des serveur multithreadés ou sur des systèmes de fichier
  43. <acronym>NFS</acronym>...
  44. </entry>
  45. </row>
  46. <row>
  47. <entry><emphasis>read_control</emphasis></entry>
  48. <entry><type>Boolean</type></entry>
  49. <entry><constant>TRUE</constant></entry>
  50. <entry>
  51. Active / désactive le contrôle de lecture&#160;: si activé, une clé
  52. de contrôle est embarquée dans le fichier de cache et cette clé est
  53. comparée avec celle calculée après la lecture.
  54. </entry>
  55. </row>
  56. <row>
  57. <entry><emphasis>read_control_type</emphasis></entry>
  58. <entry><type>String</type></entry>
  59. <entry>'crc32'</entry>
  60. <entry>
  61. Type de contrôle de lecture (seulement si le contrôle de lecture
  62. est activé). Les valeurs disponibles sont&#160;: "md5" (meilleur mais
  63. plus lent), "crc32" (un peu moins sécurisé, mais plus rapide, c'est un
  64. meilleur choix), "adler32" (nouveau choix, plus rapide que
  65. crc32),"strlen" pour un test de longueur uniquement (le plus
  66. rapide).
  67. </entry>
  68. </row>
  69. <row>
  70. <entry><emphasis>hashed_directory_level</emphasis></entry>
  71. <entry><type>Integer</type></entry>
  72. <entry>0</entry>
  73. <entry>
  74. Niveau de structure du hash du répertoire&#160;: 0 signifie "pas de
  75. hashage de la structure du répertoire", 1 signifie "un niveau de
  76. répertoire", 2 signifie "deux niveaux"... Cette option peut accélérer
  77. le cache seulement lorsque vous avez plusieurs centaines de fichiers de
  78. cache. Seuls des tests de performance spécifiques peuvent vous aider à
  79. choisir la meilleure valeur pour vous. 1 ou 2, peut-être un bon
  80. départ.
  81. </entry>
  82. </row>
  83. <row>
  84. <entry><emphasis>hashed_directory_umask</emphasis></entry>
  85. <entry><type>Integer</type></entry>
  86. <entry>0700</entry>
  87. <entry>Umask pour l'arborescence</entry>
  88. </row>
  89. <row>
  90. <entry><emphasis>file_name_prefix</emphasis></entry>
  91. <entry><type>String</type></entry>
  92. <entry>'zend_cache'</entry>
  93. <entry>
  94. Préfixe pour les fichiers mis en cache&#160;; faîtes très attention
  95. avec cette option, en cas de valeur trop générique dans le dossier de
  96. cache (comme <filename>/tmp</filename>), ceci peut causer des désastres
  97. lors du nettoyage du cache.
  98. </entry>
  99. </row>
  100. <row>
  101. <entry><emphasis>cache_file_umask</emphasis></entry>
  102. <entry><type>Integer</type></entry>
  103. <entry>0700</entry>
  104. <entry>umask des fichiers de cache.</entry>
  105. </row>
  106. <row>
  107. <entry><emphasis>metatadatas_array_max_size</emphasis></entry>
  108. <entry><type>Integer</type></entry>
  109. <entry>100</entry>
  110. <entry>
  111. Taille maximale interne pour les tableaux de métadonnées (ne
  112. changez pas cette valeur à moins de bien savoir ce que vous
  113. faîtes).
  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. Ce backend (étendu) stocke les enregistrements de cache dans une base de donnée
  124. SQLite.
  125. </para>
  126. <para>Les options disponibles sont&#160;:</para>
  127. <table id="zend.cache.backends.sqlite.table">
  128. <title>Options du backend Sqlite</title>
  129. <tgroup cols="4">
  130. <thead>
  131. <row>
  132. <entry>Option</entry>
  133. <entry>Type de données</entry>
  134. <entry>Valeur par défaut</entry>
  135. <entry>Description</entry>
  136. </row>
  137. </thead>
  138. <tbody>
  139. <row>
  140. <entry><emphasis>cache_db_complete_path (obligatoire)</emphasis></entry>
  141. <entry><type>String</type></entry>
  142. <entry><constant>NULL</constant></entry>
  143. <entry>
  144. Le chemin complet (nom du fichier inclus) de la base de donnée
  145. SQLite
  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. Désactive / Active le processus de vidange automatique. Celui-ci
  154. défragmente le fichier de base de données (et diminue sa taille) quand
  155. <methodname>clean()</methodname> ou <methodname>delete()</methodname>
  156. est appelé&#160;: 0 pour une vidange automatique&#160;; 1
  157. pour une vidange systématique (quand <methodname>clean()</methodname>
  158. ou <methodname>delete()</methodname> est
  159. appelé)&#160;; x (entier) &gt; 1 pour une vidange automatique
  160. aléatoirement 1 fois sur x <methodname>clean()</methodname> ou
  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. Ce backend (étendu) stocke les enregistrements de cache dans un serveur memcached.
  172. <ulink url="http://www.danga.com/memcached/">Memcached</ulink> est un système de cache
  173. en mémoire distribuée, de haute performance. Pour utiliser ce backend, vous devez avoir
  174. un démon memcached et l'extension
  175. <ulink url="http://pecl.php.net/package/memcache"><acronym>PECL</acronym>
  176. memcache</ulink>.
  177. </para>
  178. <para>
  179. Attention : avec ce backend, les balises ("tags") ne sont pas supportées pour le
  180. moment comme l'argument "doNotTestCacheValidity=true".
  181. </para>
  182. <para>Les options disponibles sont&#160;:</para>
  183. <table id="zend.cache.backends.memcached.table">
  184. <title>Options du backend Memcached</title>
  185. <tgroup cols="4">
  186. <thead>
  187. <row>
  188. <entry>Option</entry>
  189. <entry>Type de données</entry>
  190. <entry>Valeur par défaut</entry>
  191. <entry>Description</entry>
  192. </row>
  193. </thead>
  194. <tbody>
  195. <row>
  196. <entry><emphasis>servers</emphasis></entry>
  197. <entry><type>Array</type></entry>
  198. <entry>
  199. <command>array(array('host' => 'localhost', 'port' => 11211,
  200. 'persistent' => true, 'weight' => 1, 'timeout' => 5,
  201. 'retry_interval' => 15, 'status' => true,
  202. 'failure_callback' => '' ))</command>
  203. </entry>
  204. <entry>
  205. Un tableau de serveurs memcached&#160;; chaque serveur memcached est
  206. décrit par un tableau associatif&#160;: 'host' =&gt; (string)&#160;: le
  207. nom du serveur memcached, 'port' =&gt; (int)&#160;: le port du serveur
  208. memcached, 'persistent' =&gt; (bool)&#160;: utilisation ou pas des
  209. connexions persistantes pour ce serveur memcached, 'weight' =&gt;
  210. (int)&#160;: le poids du serveur memcached, 'timeout' =&gt;
  211. (int)&#160;: le time out du serveur memcached, 'retry_interval' =&gt;
  212. (int)&#160;: l'intervalle avant réexécution du serveur memcached,
  213. 'status' =&gt; (bool)&#160;: le statut du serveur memcached,
  214. 'failure_callback' =&gt; (callback)&#160;: le failure_callback d'échec
  215. du serveur memcached.
  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>, si vous voulez utiliser la compression à la
  224. volée
  225. </entry>
  226. </row>
  227. <row>
  228. <entry><emphasis>compatibility</emphasis></entry>
  229. <entry><type>Boolean</type></entry>
  230. <entry><constant>FALSE</constant></entry>
  231. <entry>
  232. <constant>TRUE</constant>, si vous voulez utiliser le mode de
  233. compatibilité avec les anciens serveurs&#160;/&#160;extensions memcache
  234. </entry>
  235. </row>
  236. </tbody>
  237. </tgroup>
  238. </table>
  239. </sect2>
  240. <sect2 id="zend.cache.backends.apc">
  241. <title>Zend_Cache_Backend_Apc</title>
  242. <para>
  243. Ce backend (étendu) stocke les enregistrements de cache en mémoire partagée grâce
  244. à l'extension <ulink url="http://pecl.php.net/package/APC">APC</ulink>
  245. (Alternative <acronym>PHP</acronym> Cache) qui est requise pour utiliser ce backend.
  246. </para>
  247. <para>
  248. Attention: avec ce backend, les balises ("tags") ne sont pas supportées pour le
  249. moment comme l'argument "doNotTestCacheValidity=true".
  250. </para>
  251. <para>Il n'y a pas d'options pour ce backend.</para>
  252. </sect2>
  253. <sect2 id="zend.cache.backends.xcache">
  254. <title>Zend_Cache_Backend_Xcache</title>
  255. <para>
  256. Ce backend stocke ces enregistrements de cache dans la mémoire partagée à travers
  257. l'extension <ulink url="http://xcache.lighttpd.net/">XCache</ulink>(qui est bien sûr
  258. nécessaire pour utiliser ce backend).
  259. </para>
  260. <para>
  261. Attention : avec ce backend, les balises ("tags") ne sont pas supportées pour le
  262. moment comme l'argument "doNotTestCacheValidity=true".
  263. </para>
  264. <para>Les options disponibles sont&#160;:</para>
  265. <table id="zend.cache.backends.xcache.table">
  266. <title>Options du backend Xcache</title>
  267. <tgroup cols="4">
  268. <thead>
  269. <row>
  270. <entry>Option</entry>
  271. <entry>Type de données</entry>
  272. <entry>Valeur par défaut</entry>
  273. <entry>Description</entry>
  274. </row>
  275. </thead>
  276. <tbody>
  277. <row>
  278. <entry><emphasis>user</emphasis></entry>
  279. <entry><type>String</type></entry>
  280. <entry><constant>NULL</constant></entry>
  281. <entry>
  282. <filename>xcache.admin.user</filename>, nécessaire pour la
  283. méthode <methodname>clean()</methodname>.
  284. </entry>
  285. </row>
  286. <row>
  287. <entry><emphasis>password</emphasis></entry>
  288. <entry><type>String</type></entry>
  289. <entry><constant>NULL</constant></entry>
  290. <entry>
  291. <filename>xcache.admin.pass</filename> (en texte clair non
  292. <acronym>MD5</acronym>), nécessaire pour la méthode
  293. <methodname>clean()</methodname>.
  294. </entry>
  295. </row>
  296. </tbody>
  297. </tgroup>
  298. </table>
  299. </sect2>
  300. <sect2 id="zend.cache.backends.platform">
  301. <title>Zend_Cache_Backend_ZendPlatform</title>
  302. <para>
  303. Ce backend utilise l'<acronym>API</acronym> de cache de contenu de la
  304. <ulink url="http://www.zend.com/fr/products/platform">Zend Platform</ulink>.
  305. Naturellement, pour utiliser ce backend, vous devez avoir installé une Zend Platorm.
  306. </para>
  307. <para>
  308. Ce backend supporte les balises ("tags") mais ne supporte pas le mode de
  309. nettoyage <constant>CLEANING_MODE_NOT_MATCHING_TAG</constant>.
  310. </para>
  311. <para>
  312. Spécifiez ce backend en utilisant un séparateur de mot - "-", ".", " " ou "_" -
  313. entre les mots "Zend" et "Platform" quand vous utilisez la méthode
  314. <methodname>Zend_Cache::factory()</methodname>&#160;:
  315. </para>
  316. <programlisting language="php"><![CDATA[
  317. $cache = Zend_Cache::factory('Core', 'Zend Platform');
  318. ]]></programlisting>
  319. <para>Il n'y a pas d'options pour ce backend.</para>
  320. </sect2>
  321. <sect2 id="zend.cache.backends.twolevels">
  322. <title>Zend_Cache_Backend_TwoLevels</title>
  323. <para>
  324. Ce backend (étendu) est un hybride. Il stocke les enregistrements de cache dans
  325. deux autres backends&#160;: un rapide (mais limité) comme Apc, Memcache... et un plus
  326. "lent" comme File, Sqlite...
  327. </para>
  328. <para>
  329. Ce backend utilise le paramètre priorité (fourni au niveau du frontend au moment
  330. d'un enregistrement) et l'espace restant dans le backend rapide pour optimiser
  331. l'utilisation de ces deux backends.
  332. </para>
  333. <para>
  334. Spécifiez ce backend avec un séparateur de mots - "-", ".", " ", ou "_" - entre les
  335. mots "Two" et "Levels" quand vous utilisez la méthode
  336. <methodname>Zend_Cache::factory()</methodname>&#160;:
  337. </para>
  338. <programlisting language="php"><![CDATA[
  339. $cache = Zend_Cache::factory('Core', 'Two Levels');
  340. ]]></programlisting>
  341. <para>Les options disponibles sont :</para>
  342. <table id="zend.cache.backends.twolevels.table">
  343. <title>Options du backend TwoLevels</title>
  344. <tgroup cols="4">
  345. <thead>
  346. <row>
  347. <entry>Option</entry>
  348. <entry>Type de données</entry>
  349. <entry>Valeur par défaut</entry>
  350. <entry>Description</entry>
  351. </row>
  352. </thead>
  353. <tbody>
  354. <row>
  355. <entry><emphasis>slow_backend</emphasis></entry>
  356. <entry><type>String</type></entry>
  357. <entry>File</entry>
  358. <entry>le nom du backend "lent"</entry>
  359. </row>
  360. <row>
  361. <entry><emphasis>fast_backend</emphasis></entry>
  362. <entry><type>String</type></entry>
  363. <entry>Apc</entry>
  364. <entry>le nom du backend "rapide"</entry>
  365. </row>
  366. <row>
  367. <entry><emphasis>slow_backend_options</emphasis></entry>
  368. <entry><type>Array</type></entry>
  369. <entry><methodname>array()</methodname></entry>
  370. <entry>les options du backend "lent"</entry>
  371. </row>
  372. <row>
  373. <entry><emphasis>fast_backend_options</emphasis></entry>
  374. <entry><type>Array</type></entry>
  375. <entry><methodname>array()</methodname></entry>
  376. <entry>les options du backend "rapide"</entry>
  377. </row>
  378. <row>
  379. <entry><emphasis>slow_backend_custom_naming</emphasis></entry>
  380. <entry><type>Boolean</type></entry>
  381. <entry><constant>FALSE</constant></entry>
  382. <entry>
  383. si <constant>TRUE</constant>, l'argument "slow_backend" est
  384. utilisé en tant que nom complet de classe&#160;; si
  385. <constant>FALSE</constant>, l'argument frontend est utilisé concaténé à
  386. "<classname>Zend_Cache_Backend_&lt;...&gt;</classname>"
  387. </entry>
  388. </row>
  389. <row>
  390. <entry><emphasis>fast_backend_custom_naming</emphasis></entry>
  391. <entry><type>Boolean</type></entry>
  392. <entry><constant>FALSE</constant></entry>
  393. <entry>
  394. si <constant>TRUE</constant>, l'argument "fast_backend" est
  395. utilisé en tant que nom complet de classe&#160;; si
  396. <constant>FALSE</constant>, l'argument frontend est utilisé concaténé à
  397. "<classname>Zend_Cache_Backend_&lt;...&gt;</classname>"
  398. </entry>
  399. </row>
  400. <row>
  401. <entry><emphasis>slow_backend_autoload</emphasis></entry>
  402. <entry><type>Boolean</type></entry>
  403. <entry><constant>FALSE</constant></entry>
  404. <entry>
  405. si <constant>TRUE</constant>, il n'y aura pas de require_once pour le
  406. "slow_backend" (utile seulement pour les backends
  407. personnalisés)
  408. </entry>
  409. </row>
  410. <row>
  411. <entry><emphasis>fast_backend_autoload</emphasis></entry>
  412. <entry><type>Boolean</type></entry>
  413. <entry><constant>FALSE</constant></entry>
  414. <entry>
  415. si <constant>TRUE</constant>, il n'y aura pas de require_once pour le
  416. "fast_backend" (utile seulement pour les backends
  417. personnalisés)
  418. </entry>
  419. </row>
  420. <row>
  421. <entry><emphasis>auto_refresh_fast_cache</emphasis></entry>
  422. <entry><type>Boolean</type></entry>
  423. <entry><constant>TRUE</constant></entry>
  424. <entry>
  425. si <constant>TRUE</constant>, rafraîchissement automatique du cache
  426. rapide quand un enregistrement est appelé
  427. </entry>
  428. </row>
  429. <row>
  430. <entry><emphasis>stats_update_factor</emphasis></entry>
  431. <entry><type>Integer</type></entry>
  432. <entry>10</entry>
  433. <entry>
  434. désactive&#160;/&#160;personnalise le calcul du pourcentage de
  435. remplissage du backend rapide (lors d'une sauvegarde d'un enregistrement
  436. dans le cache, le calcul du remplissage est effectué aléatoirement
  437. 1 fois sur x écritures de cache)
  438. </entry>
  439. </row>
  440. </tbody>
  441. </tgroup>
  442. </table>
  443. </sect2>
  444. <sect2 id="zend.cache.backends.zendserver">
  445. <title> Zend_Cache_Backend_ZendServer_Disk et Zend_Cache_Backend_ZendServer_ShMem </title>
  446. <para>
  447. Ces backends utilisent les fonctionnalités de mise en cache de
  448. <ulink url="http://www.zend.com/en/products/server/downloads-all?zfs=zf_download">Zend
  449. Server</ulink>pour stocker les données.
  450. </para>
  451. <para>
  452. Attention : avec ces backends ne supportent pas les balises ("tags") pour le
  453. moment de même que l'argument "doNotTestCacheValidity=true".
  454. </para>
  455. <para>
  456. Ces backends fonctionnent seulement dans l'environnement de Zend Server pour les
  457. pages requêtées à travers <acronym>HTTP</acronym> ou <acronym>HTTPS</acronym> et ne
  458. fonctionnent pas pour les scripts exécutés en ligne de commande.
  459. </para>
  460. <para>
  461. Spécifiez ce backend en utilisant le paramètre <emphasis>customBackendNaming</emphasis>
  462. à <constant>TRUE</constant> quand vous utilisez la méthode
  463. <methodname>Zend_Cache::factory()</methodname>&#160;:
  464. </para>
  465. <programlisting language="php"><![CDATA[
  466. $cache = Zend_Cache::factory('Core', 'Zend_Cache_Backend_ZendServer_Disk',
  467. $frontendOptions, $backendOptions, false, true);
  468. ]]></programlisting>
  469. <para>Il n'y a pas d'options pour ce backend.</para>
  470. </sect2>
  471. <sect2 id="zend.cache.backends.static">
  472. <title>Zend_Cache_Backend_Static</title>
  473. <para>
  474. This backend works in concert with <classname>Zend_Cache_Frontend_Capture</classname>
  475. (the two must be used together) to save the output from requests as static files. This
  476. means the static files are served directly on subsequent requests without any
  477. involvement of <acronym>PHP</acronym> or Zend Framework at all.
  478. </para>
  479. <note>
  480. <para>
  481. <classname>Zend_Cache_Frontend_Capture</classname> operates
  482. by registering a callback function to be called
  483. when the output buffering it uses is cleaned. In order for this to operate
  484. correctly, it must be the final output buffer in the request. To guarantee
  485. this, the output buffering used by the Dispatcher <emphasis>must</emphasis> be
  486. disabled by calling <classname>Zend_Controller_Front</classname>'s
  487. <methodname>setParam()</methodname> method, for example,
  488. <command>$front->setParam('disableOutputBuffering', true);</command> or adding
  489. "resources.frontcontroller.params.disableOutputBuffering = true"
  490. to your bootstrap configuration file (assumed <acronym>INI</acronym>) if using
  491. <classname>Zend_Application</classname>.
  492. </para>
  493. </note>
  494. <para>
  495. The benefits of this cache include a large throughput increase since
  496. all subsequent requests return the static file and don't need any
  497. dynamic processing. Of course this also has some disadvantages. The
  498. only way to retry the dynamic request is to purge the cached file
  499. from elsewhere in the application (or via a cronjob if timed). It
  500. is also restricted to single-server applications where only one
  501. filesystem is used. Nevertheless, it can be a powerful means of
  502. getting more performance without incurring the cost of a proxy on
  503. single machines.
  504. </para>
  505. <para>
  506. Before describing its options, you should note this needs some
  507. changes to the default <filename>.htaccess</filename> file in order for requests to be
  508. directed to the static files if they exist. Here's an example of
  509. a simple application caching some content, including two specific
  510. feeds which need additional treatment to serve a correct
  511. Content-Type header:
  512. </para>
  513. <programlisting language="text"><![CDATA[
  514. AddType application/rss+xml .xml
  515. AddType application/atom+xml .xml
  516. RewriteEngine On
  517. RewriteCond %{REQUEST_URI} feed/rss$
  518. RewriteCond %{DOCUMENT_ROOT}/cached/%{REQUEST_URI}.xml -f
  519. RewriteRule .* cached/%{REQUEST_URI}.xml [L,T=application/rss+xml]
  520. RewriteCond %{REQUEST_URI} feed/atom$
  521. RewriteCond %{DOCUMENT_ROOT}/cached/%{REQUEST_URI}.xml -f
  522. RewriteRule .* cached/%{REQUEST_URI}.xml [L,T=application/atom+xml]
  523. RewriteCond %{DOCUMENT_ROOT}/cached/index.html -f
  524. RewriteRule ^/*$ cached/index.html [L]
  525. RewriteCond %{DOCUMENT_ROOT}/cached/%{REQUEST_URI}.(html|xml|json|opml|svg) -f
  526. RewriteRule .* cached/%{REQUEST_URI}.%1 [L]
  527. RewriteCond %{REQUEST_FILENAME} -s [OR]
  528. RewriteCond %{REQUEST_FILENAME} -l [OR]
  529. RewriteCond %{REQUEST_FILENAME} -d
  530. RewriteRule ^.*$ - [NC,L]
  531. RewriteRule ^.*$ index.php [NC,L]
  532. ]]></programlisting>
  533. <para>
  534. The above assumes static files are cached to the directory
  535. <filename>./public/cached</filename>. We'll cover the option setting this location,
  536. "public_dir", below.
  537. </para>
  538. <para>
  539. Due to the nature of static file caching, the backend class offers two additional
  540. methods: <methodname>remove()</methodname> and
  541. <methodname>removeRecursively()</methodname>. Both accept a request
  542. <acronym>URI</acronym>, which when mapped to the "public_dir" where static files are
  543. cached, and has a pre-stored extension appended, provides the name of either a static
  544. file to delete, or a directory path to delete recursively. Due to the
  545. restraints of <classname>Zend_Cache_Backend_Interface</classname>, all
  546. other methods such as <methodname>save()</methodname> accept an ID which
  547. is calculated by applying <methodname>bin2hex()</methodname> to a request
  548. <acronym>URI</acronym>.
  549. </para>
  550. <para>
  551. Given the level at which static caching operates, static file caching is addressed for
  552. simpler use with the <classname>Zend_Controller_Action_Helper_Cache</classname> action
  553. helper. This helper assists in setting which actions of a controller to cache, with what
  554. tags, and with which extension. It also offers methods for purging the cache by request
  555. <acronym>URI</acronym> or tag. Static file caching is also assisted by
  556. <classname>Zend_Cache_Manager</classname> which includes pre-configured configuration
  557. templates for a static cache (as <constant>Zend_Cache_Manager::PAGECACHE</constant> or
  558. "page"). The defaults therein can be configured as needed to set up a "public_dir"
  559. location for caching, etc.
  560. </para>
  561. <note>
  562. <para>
  563. It should be noted that the static cache actually uses a secondary cache to store
  564. tags (obviously we can't store them elsewhere since a static cache does not invoke
  565. <acronym>PHP</acronym> if working correctly). This is just a standard Core cache,
  566. and should use a persistent backend such as File or TwoLevels (to take advantage of
  567. memory storage without sacrificing permanent persistance). The backend includes the
  568. option "tag_cache" to set this up (it is obligatory), or the
  569. <methodname>setInnerCache()</methodname> method.
  570. </para>
  571. </note>
  572. <table id="zend.cache.backends.static.table">
  573. <title>Static Backend Options</title>
  574. <tgroup cols="4">
  575. <thead>
  576. <row>
  577. <entry>Option</entry>
  578. <entry>Data Type</entry>
  579. <entry>Default Value</entry>
  580. <entry>Description</entry>
  581. </row>
  582. </thead>
  583. <tbody>
  584. <row>
  585. <entry><emphasis>public_dir</emphasis></entry>
  586. <entry><type>String</type></entry>
  587. <entry><constant>NULL</constant></entry>
  588. <entry>
  589. Directory where to store static files. This must exist
  590. in your public directory.
  591. </entry>
  592. </row>
  593. <row>
  594. <entry><emphasis>file_locking</emphasis></entry>
  595. <entry><type>Boolean</type></entry>
  596. <entry><constant>TRUE</constant></entry>
  597. <entry>
  598. Enable or disable file_locking : Can avoid cache corruption under
  599. bad circumstances but it doesn't help on multithread webservers
  600. or on <acronym>NFS</acronym> filesystems...
  601. </entry>
  602. </row>
  603. <row>
  604. <entry><emphasis>read_control</emphasis></entry>
  605. <entry><type>Boolean</type></entry>
  606. <entry><constant>TRUE</constant></entry>
  607. <entry>
  608. Enable / disable read control : if enabled, a control key is
  609. embedded in the cache file and this key is compared with the
  610. one calculated after the reading.
  611. </entry>
  612. </row>
  613. <row>
  614. <entry><emphasis>read_control_type</emphasis></entry>
  615. <entry><type>String</type></entry>
  616. <entry>'crc32'</entry>
  617. <entry>
  618. Type of read control (only if read control is enabled). Available values
  619. are : 'md5' (best but slowest), 'crc32' (lightly less safe but faster,
  620. better choice), 'adler32' (new choice, faster than crc32),
  621. 'strlen' for a length only test (fastest).
  622. </entry>
  623. </row>
  624. <row>
  625. <entry><emphasis>cache_file_umask</emphasis></entry>
  626. <entry><type>Integer</type></entry>
  627. <entry>0700</entry>
  628. <entry>umask for cached files.</entry>
  629. </row>
  630. <row>
  631. <entry><emphasis>cache_directory_umask</emphasis></entry>
  632. <entry><type>Integer</type></entry>
  633. <entry>0700</entry>
  634. <entry>Umask for directories created within public_dir.</entry>
  635. </row>
  636. <row>
  637. <entry><emphasis>file_extension</emphasis></entry>
  638. <entry><type>String</type></entry>
  639. <entry>'<filename>.html</filename>'</entry>
  640. <entry>
  641. Default file extension for static files created. This can be
  642. configured on the fly, see
  643. <methodname>Zend_Cache_Backend_Static::save()</methodname> though
  644. generally it's recommended to rely on
  645. <classname>Zend_Controller_Action_Helper_Cache</classname> when
  646. doing so since it's simpler that way than messing with
  647. arrays or serialization manually.
  648. </entry>
  649. </row>
  650. <row>
  651. <entry><emphasis>index_filename</emphasis></entry>
  652. <entry><type>String</type></entry>
  653. <entry>'index'</entry>
  654. <entry>
  655. If a request <acronym>URI</acronym> does not contain sufficient
  656. information to construct a static file (usually this means an index
  657. call, e.g. <acronym>URI</acronym> of '/'), the index_filename is used
  658. instead. So '' or '/' would map to '<filename>index.html</filename>'
  659. (assuming the default file_extension is '<filename>.html</filename>').
  660. </entry>
  661. </row>
  662. <row>
  663. <entry><emphasis>tag_cache</emphasis></entry>
  664. <entry><type>Object</type></entry>
  665. <entry><constant>NULL</constant></entry>
  666. <entry>
  667. Used to set an 'inner' cache utilised to store tags
  668. and file extensions associated with static files. This
  669. <emphasis>must</emphasis> be set or the static cache cannot be tracked
  670. and managed.
  671. </entry>
  672. </row>
  673. <row>
  674. <entry><emphasis>disable_caching</emphasis></entry>
  675. <entry><type>Boolean</type></entry>
  676. <entry><constant>FALSE</constant></entry>
  677. <entry>
  678. If set to <constant>TRUE</constant>, static files will not be cached.
  679. This will force all requests to be dynamic even if marked
  680. to be cached in Controllers. Useful for debugging.
  681. </entry>
  682. </row>
  683. </tbody>
  684. </tgroup>
  685. </table>
  686. </sect2>
  687. </sect1>