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