29-11-2011 : Remettre dans le débat politique les principes du Conseil National de la Résistance
17-02-2012 : Pétition pour une protection de l’apiculture et des consommateurs face au lobby des OGM
Logo de mon site
Logo de mon site
Faire un don




Right menu

Logo du site ez.no  Logo XHTML 1.O du W3C  Logo XHTML 1.O du W3C  Site francophone officiel de Firefox
zero papier grâce aux catalogues et promos en ligne de bonial

Static cache / Cache statique

Date de publication: le samedi 12 avril 2008 à 18h08
Dernière modification: par Pascal BOYER le dimanche 26 septembre 2010 à 23h08
« Article précédent: Caching overview / Généralités sur le système de cache
» Article suivant: Cacheable headers / En-têtes pouvant être mis en cache

25/01/2007  

The static caching feature is available in eZ Publish 3.6 and higher. It uses Apache rewrite rules to check if a static file exists, then serves it straight from disk (and thus avoids using the PHP processor). This means that the complete page can be stored as an XHTML file. In the case that the file does not exist, the request is simply sent through to eZ Publish, where there could still be cached elements in the template file as described above.
La fonction de cache statique, présente dans toutes les versions 3.6 et ultérieures de eZ Publish, utilise les règles de réécriture du serveur Apache pour contrôler l'existence d'un fichier statique. Le cas échéant, ce dernier est servi directement à partir du disque dur (évitant ainsi de recourir à l'utilisation du processeur PHP). Cela signifie que la page entière peut être stockée en tant que fichier XHTML. Lorsque le fichier n'existe pas, la requête est simplement envoyée à eZ Publish où il peut déjà exister, comme décrit précédemment, des éléments cachés du template.

Using the static cache can lead to greatly improved performance, but it restricts some functionality. It is normal to run the static cache in combination with fully dynamic pages.
Bien que l'utilisation du cache statique puisse grandement améliorer les performances, cela restreint, par ailleurs, certaines fonctionnalités. Il est normal d'activer le cache statique conjointement à l'utilisation de pages entièrement dynamiques.

You can run the static cache on part of your site if:
Vous pouvez activer le cache statique sur certaines parties de votre site si:

  • it is not personalized
    elles ne sont pas personnalisées,
  • it does not include dynamic elements (such as displaying the current time)
    elles n'incluent pas d'éléments dynamiques (tel que l'affichage de l'heure courante)
  • it is publicly available and not restricted by permissions
    elles sont publiquement accessibles et restreintes par aucune politique de permission.

Since most eZ Publish sites use one or all of the features above for at least part of the site, you can benefit by using the static cache for those parts. A typical scenario is:
Puisque la plupart des sites eZ Publish utilisent l'une ou toutes les fonctionnalités ci-dessus dans au moins l'une des parties du site, vous pouvez tirer bénéfice du cache statique pour les parties concernées. Un scénario courant est:

  • Company information: static
    Informations sur l'entreprise: statique
  • Press releases: static
    Revue de presse: statique
  • Webshop: dynamic
    Commerce en ligne: statique
  • Restricted partner section: dynamic
    Section du site en accès restreint: dynamique
  • Community forums: dynamic
    Forums: dynamique

Static cache with one siteaccess / Cache statique avec un seul siteaccess

In this situation, there is one siteaccess (in this example, ez.no) for which we want to implement static caching. First, modify the Apache VHOST configuration to include the rewrite rules below. You should only add rewrite rules for the VHOSTs for which you want to have static caching. In reality, this means that for each siteaccess that you want to cache, you need a different VHOST block in the Apache configuration.
Si l'on souhaite mettre en oeuvre le système de cache statique pour un unique siteaccess (dans cet exemple: ez.no), il est tout d'abord nécessaire de modifier la configuration du VirtualHost de Apache pour y inclure les règles de réécriture présentées ci-après. Vous ne devez ajouter des règles de réécriture qu'aux sections VirtualHost pour lesquelles vous souhaitez activer le cache statique. Cela signifie, en réalité, que vous devez définir, dans le fichier de configuration de Apache, une section VirtualHost pour chaque siteaccess pour lequel vous souhaitez activer le cache statique:

RewriteEngine On
RewriteCond /dat/ez.no/static/index.html -f
RewriteRule ^/$ /static/index.html [L]
RewriteCond /dat/ez.no/static/index.html -f
RewriteRule ^$ /static/index.html [L]
 
RewriteCond %{REQUEST_METHOD} !^POST$
RewriteCond /dat/ez.no/static$1/index.html -f
RewriteRule ^(.*)$ /static$1/index.html [L]
 
RewriteRule !\.(gif|css|jpg|png|jar|ico|js)$ /index.php 

You will need to change /dat/ez.no to the path corresponding to the root location of your eZ Publish installation.
Remplacer /dat/ez.no par le chemin correspondant au répertoire racine de votre serveur eZ Publish.

In settings/override/site.ini.append.php, add the following settings to enable the static caching process:
Ajoutez ensuite au fichier de surcharge settings/override/ site.ini.append.php les paramètres suivants pour activer le processus de cache statique:

[ContentSettings]
StaticCache=enabled 

In settings/override/staticcache.ini.append.php, configure the details about the host and the pages to cache:
Toujours dans le fichier settings/override/ staticcache.ini.append.php, définissez les détails de l'hôte et des pages à mettre en cache:

[CacheSettings]
HostName=tequila:1400
StaticStorageDir=static
MaxCacheDepth=4
 
# A list of url's to cache
CachedURLArray[]=/* 

HostName is the host where the pages are viewed. The static cache feature uses this to retrieve the generated content to store as cache files.
HostName contient le nom du serveur eZ Publish. La fonction de cache statique utilise la valeur de ce paramètre pour retrouver le contenu généré afin de le stocker en tant que fichiers de cache.

StaticStorageDir is the directory where the static cache files are stored. It is relative to the root directory of your eZ Publish installation. This needs to match the part between /dat/ez.no/ and $1/index.html in the rewrite rules above.
StaticStorageDir définit le répertoire dans lequel sont stockés les fichiers de cache. Le chemin est relatif à la racine du répertoire d'installation de eZ Publish et doit donc correspondre à la partie comprise entre /dat/ez.no et $1/index.html dans les règles de réécriture explicitées plus haut.

MaxCacheDepth is the maximum number of directory levels to cache, as seen from the root of your installation.
MaxCacheDepth désigne, en partant de la racine du répertoire d'installation de eZ Publish, le nombre maximum de sous-répertoires à mettre en cache.

CachedURLArray specifies the parts of your site that are allowed to be statically cached. Use / or /products to cache only one page (in this example, the front page and the /products page). You can also use wildcards; for example, with "/products*" all URLs below /products are cached.
CachedURLArray contient les parties de votre site web pour lesquelles le cache statique doit être utilisé. Utilisez / ou /products pour que le cache statique n'affecte qu'une seule page (dans cet exemple, la page d'accueil et la page /products). Vous pouvez également employer les caractères génériques: par exemple, la syntaxe " /products*" permet de cacher tous les URI commençant par /products.

Static cache with multiple siteaccesses / Cache statique avec plusieurs siteaccess

In this example there are two site languages: English and French. The siteaccesses are called news_en and news_fr.
Dans cet exemple nous considérons deux langues de site: l' anglais et le français et les siteaccess sont nommés news_en et news_fr

In this case, we use the following rewrite rules, where the root directory of the eZ Publish installation is /home/httpd/ez-3.6:
Dans ce cas de figure, nous utilisons les règles de réécritures ci-dessous où le répertoire racine de eZ Publish est /home/httpd/ez-3.6:

RewriteEngine On
RewriteLog /tmp/rewrite
RewriteLogLevel 4
 
RewriteCond /home/httpd/ez-3.6/static/news_en/index.html -f
RewriteRule ^/$ /static/news_en/index.html [L]
RewriteCond /home/httpd/ez-3.6/static/news_en/index.html -f
RewriteRule ^$ /static/news_en/index.html [L]
 
RewriteCond /home/httpd/ez-3.6/static/news_fr/index.html -f
RewriteRule ^/$ /static/news_fr/index.html [L]
RewriteCond /home/httpd/ez-3.6/static/news_fr/index.html -f
RewriteRule ^$ /static/news_fr/index.html [L]
 
RewriteCond %{REQUEST_METHOD} !^POST$
RewriteCond /home/httpd/ez-3.6/static$1/index.html -f
RewriteRule ^(.*)$ /static$1/index.html [L]
 
RewriteRule !\.(gif|css|jpg|png|jar|ico|js)$ /index.php 

The following settings need to be specified:
Les paramètres suivants doivent également être définis:

In settings/override/site.ini.append.php:
Dans le fichier de surcharge globale settings/override/ site.ini.append.php :

[ContentSettings]
StaticCache=enabled 

In settings/siteaccess/news_en/staticcache.ini.append.php:
Dans le fichier de surcharge settings/siteaccess/news_en/ staticcache.ini.append.php :

[CacheSettings]
StaticStorageDir=static/news_en 

In settings/siteaccess/news_fr/staticcache.ini.append.php:
Dans le fichier de surcharge settings/siteaccess/news_fr/ staticcache.ini.append.php :

[CacheSettings]
StaticStorageDir=static/news_fr 

Make sure that the part after static is the same as the name of the siteaccess! You can of course change static to something else, but make sure it is the same as in the rewrite rules.
Assurez-vous que la partie placée après static corresponde bien au nom du siteaccess. Vous pouvez bien sûr remplacer static par n'importe quoi d'autre mais assurez-vous alors qu'il corresponde bien à ce que vous avez indiqué dans les règles de réécriture.

In settings/override/staticcache.ini.append.php, we then configure the static cache mechanism:
Dans le fichier de surcharge globale settings/override/ staticcache.ini.append.php , nous devons à présent configurer le mécanisme de cache statique:

[CacheSettings]
HostName=localhost
MaxCacheDepth=4
 
# A list of url's to cache
CachedURLArray[]
CachedURLArray[]=/news*
CachedURLArray[]=/weblog*
 
CachedSiteAccesses[]
CachedSiteAccesses[]=news_en
CachedSiteAccesses[]=news_fr 

This caches the /news and /weblog subtrees of the site on the host localhost with a maximum folder depth of 4.
Le paramétrage ci-dessus permet de cacher au maximum 4 sous-niveaux des sous-répertoires /news et /weblog du site hébergé par l'hôte localhost.

Generating cache files / Génération des fichiers de cache

Static cache files are created in two ways:
Les fichiers de cache statique sont générés de deux façons:

  1. by publishing an object
    Lors de la publication d'un objet (et non lors de sa modification - de même, le fichier statique n'est pas supprimé lors de la suppression de l'objet)
  2. by running the makestaticcache.php script
    Lors de l'exécution du script makestaticcache.php

The bin/php/makestaticcache.php script generates all the static cache files for a specific siteaccess. In our example with ez.no, use the following command to generate the cache files: 
Le script bin/php/ makestaticcache.php  génère tous les fichiers de cache statique d'un siteaccess donné. Dans notre exemple, utilisez la commande suivante pour générer tous les fichiers de cache du siteaccess ez.no:

php bin/php/makestaticcache.php -s ez.no

If you want to re-create all cache files, even the ones that already exist, use the -f parameter to force the generation of all static cache files. The command below regenerates all static cache files for both siteaccesses from our second example: 
Si vous désirez recréer tous les fichiers de cache, même ceux qui existent déjà, utilisez le paramètre -f pour forcer la génération de tous les fichiers de cache statique. La commande ci-après génère tous les fichiers de cache statique des deux siteaccess de notre second exemple:

php bin/php/makestaticcache.php -f

Commentaires