2004-04-13 11:47:32 +00:00
|
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
|
|
|
<!-- $Revision$ -->
|
2004-12-26 20:05:31 +00:00
|
|
|
|
<!-- EN-Revision: 1.2 Maintainer: yannick Status: ready -->
|
2004-05-23 15:50:53 +00:00
|
|
|
|
<sect1 id="caching.setting.up">
|
|
|
|
|
<title>Param<EFBFBD>trer le cache</title>
|
|
|
|
|
<para>
|
2004-12-26 20:05:31 +00:00
|
|
|
|
La premi<6D>re chose <20> faire est d'activer le cache. Cela est fait en
|
2004-05-23 15:50:53 +00:00
|
|
|
|
mettant <link linkend="variable.caching">$caching</link> = true
|
|
|
|
|
(ou 1).
|
|
|
|
|
</para>
|
|
|
|
|
<example>
|
2004-12-26 20:05:31 +00:00
|
|
|
|
<title>Activation du cache</title>
|
|
|
|
|
<programlisting role="php">
|
|
|
|
|
<![CDATA[
|
|
|
|
|
<?php
|
2004-04-13 11:47:32 +00:00
|
|
|
|
require('Smarty.class.php');
|
|
|
|
|
$smarty = new Smarty;
|
|
|
|
|
|
|
|
|
|
$smarty->caching = true;
|
|
|
|
|
|
2004-12-26 20:05:31 +00:00
|
|
|
|
$smarty->display('index.tpl');
|
|
|
|
|
?>
|
|
|
|
|
]]>
|
|
|
|
|
</programlisting>
|
2004-05-23 15:50:53 +00:00
|
|
|
|
</example>
|
|
|
|
|
<para>
|
|
|
|
|
Avec le cache activ<69>, la fonction display('index.tpl') va afficher
|
|
|
|
|
le template mais sauvegardera par la m<>me occasion une copie du r<>sultat
|
|
|
|
|
dans un fichier (de cache) du r<>pertoire
|
|
|
|
|
<link linkend="variable.cache.dir">$cache_dir</link>. Au prochain appel de
|
2004-12-26 20:05:31 +00:00
|
|
|
|
display('index.tpl'), le fichier de cache sera pr<70>f<EFBFBD>r<EFBFBD> <20> la r<>utilisation
|
|
|
|
|
du template.
|
|
|
|
|
</para>
|
|
|
|
|
<note>
|
|
|
|
|
<title>Note technique</title>
|
2004-05-23 15:50:53 +00:00
|
|
|
|
<para>
|
2004-12-26 20:05:31 +00:00
|
|
|
|
Les fichiers situ<74>s dans $cache_dir sont nomm<6D>s de la m<>me fa<66>on que les templates.
|
|
|
|
|
Bien qu'ils aient une extension ".php", ils ne sont pas vraiment ex<65>cutable.
|
|
|
|
|
N'<27>ditez surtout pas ces fichiers !
|
2004-05-23 15:50:53 +00:00
|
|
|
|
</para>
|
2004-12-26 20:05:31 +00:00
|
|
|
|
</note>
|
|
|
|
|
<para>
|
|
|
|
|
Tout fichier de cache a une dur<75>e de vie limit<69>e d<>termin<69>e par <link
|
|
|
|
|
linkend="variable.cache.lifetime">$cache_lifetime</link>. La valeur par
|
|
|
|
|
d<>faut est 3600 secondes, i.e. 1 heure. Une fois que cette dur<75>e est
|
|
|
|
|
d<>pass<73>e, le cache est reg<65>n<EFBFBD>r<EFBFBD>. Il est possible de donner
|
|
|
|
|
une dur<75>e d'expiration propre <20> chaque fichier de cache en r<>glant
|
|
|
|
|
$caching = 2.
|
|
|
|
|
Se reporter <20> la documentation de <link
|
|
|
|
|
linkend="variable.cache.lifetime">$cache_lifetime</link> pour plus de
|
|
|
|
|
d<>tails.
|
|
|
|
|
</para>
|
|
|
|
|
<example>
|
|
|
|
|
<title>R<EFBFBD>glage individuel de cache_lifetime</title>
|
|
|
|
|
<programlisting role="php">
|
|
|
|
|
<![CDATA[
|
|
|
|
|
<?php
|
2004-04-13 11:47:32 +00:00
|
|
|
|
require('Smarty.class.php');
|
|
|
|
|
$smarty = new Smarty;
|
|
|
|
|
|
|
|
|
|
$smarty->caching = 2; // r<>gler la dur<75>e de vie individuellement
|
|
|
|
|
|
|
|
|
|
// r<>gle la dur<75>e de vie du cache a 15 minutes pour index.tpl
|
|
|
|
|
$smarty->cache_lifetime = 300;
|
|
|
|
|
$smarty->display('index.tpl');
|
|
|
|
|
|
|
|
|
|
// r<>gle la dur<75>e de vie du cache a 1 heure pour home.tpl
|
|
|
|
|
$smarty->cache_lifetime = 3600;
|
|
|
|
|
$smarty->display('home.tpl');
|
|
|
|
|
|
|
|
|
|
// NOTE : le r<>glage suivant ne fonctionne pas quand $caching = 2. La dur<75>e de vie
|
|
|
|
|
// du fichier de cache de home.tpl a d<>ja <20>t<EFBFBD> r<>gl<67>e a 1 heure et ne respectera
|
|
|
|
|
// plus la valeur de $cache_lifetime. Le cache de home.tpl expirera toujours
|
|
|
|
|
// dans 1 heure.
|
|
|
|
|
$smarty->cache_lifetime = 30; // 30 secondes
|
2004-12-26 20:05:31 +00:00
|
|
|
|
$smarty->display('home.tpl');
|
|
|
|
|
?>
|
|
|
|
|
]]>
|
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
<para>
|
|
|
|
|
Si <link linkend="variable.compile.check">$compile_check</link> est actif,
|
|
|
|
|
chaque fichier de template et de configuration qui a un rapport
|
|
|
|
|
avec le fichier de cache sera v<>rifi<66> pour d<>tecter une <20>ventuelle
|
|
|
|
|
modification. Si l'un de ces fichiers a <20>t<EFBFBD> modifi<66> depuis que le fichier de cache a <20>t<EFBFBD>
|
|
|
|
|
g<>n<EFBFBD>r<EFBFBD>, le cache est imm<6D>diatement reg<65>n<EFBFBD>r<EFBFBD>. Ce processus est couteux, donc,
|
|
|
|
|
pour des raisons de performances, mettez ce param<61>tre <20> false pour une application
|
|
|
|
|
en production.
|
|
|
|
|
</para>
|
|
|
|
|
<example>
|
|
|
|
|
<title>Activation de $compile_check</title>
|
|
|
|
|
<programlisting role="php">
|
|
|
|
|
<![CDATA[
|
|
|
|
|
<?php
|
2004-04-13 11:47:32 +00:00
|
|
|
|
require('Smarty.class.php');
|
|
|
|
|
$smarty = new Smarty;
|
|
|
|
|
|
|
|
|
|
$smarty->caching = true;
|
|
|
|
|
$smarty->compile_check = true;
|
|
|
|
|
|
2004-12-26 20:05:31 +00:00
|
|
|
|
$smarty->display('index.tpl');
|
|
|
|
|
?>
|
|
|
|
|
]]>
|
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
<para>
|
|
|
|
|
Si <link linkend="variable.force.compile">$force_compile</link> est actif,
|
|
|
|
|
les fichiers de cache sont toujours reg<65>n<EFBFBD>r<EFBFBD>s. Ceci revient finalement <20>
|
|
|
|
|
d<>sactiver le cache. $force_compile est utilis<69> <20> des fins de d<>bogage,
|
|
|
|
|
un moyen plus efficace de d<>sactiver le cache est de r<>gler
|
|
|
|
|
<link linkend="variable.caching">$caching</link> = false (ou 0).
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
La fonction <link linkend="api.is.cached">is_cached()</link> permet
|
|
|
|
|
de tester si un template a ou non un fichier de cache valide.
|
|
|
|
|
Si vous disposez d'un template en cache qui requiert une requ<71>te
|
|
|
|
|
<20> une base de donn<6E>es, vous pouvez utiliser cette m<>thode plut<75>t
|
|
|
|
|
que $compile_check.
|
|
|
|
|
</para>
|
|
|
|
|
<example>
|
|
|
|
|
<title>Exemple avec is_cached()</title>
|
|
|
|
|
<programlisting role="php">
|
|
|
|
|
<![CDATA[
|
|
|
|
|
<?php
|
2004-04-13 11:47:32 +00:00
|
|
|
|
require('Smarty.class.php');
|
|
|
|
|
$smarty = new Smarty;
|
|
|
|
|
|
|
|
|
|
$smarty->caching = true;
|
|
|
|
|
|
|
|
|
|
if(!$smarty->is_cached('index.tpl')) {
|
|
|
|
|
// pas de cache disponible, on assigne
|
2004-12-26 20:05:31 +00:00
|
|
|
|
$contents = get_database_contents();
|
|
|
|
|
$smarty->assign($contents);
|
2004-04-13 11:47:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-12-26 20:05:31 +00:00
|
|
|
|
$smarty->display('index.tpl');
|
|
|
|
|
?>
|
|
|
|
|
]]>
|
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
<para>
|
|
|
|
|
Vous pouvez rendre dynamiques seulement certaines parties d'une
|
|
|
|
|
page avec la fonction de template <link
|
|
|
|
|
linkend="language.function.insert">insert</link>.
|
|
|
|
|
Imaginons que toute une page doit <20>tre mise en cache <20> part
|
|
|
|
|
une banni<6E>re en bas <20> droite. En utilisant une fonction insert pour la
|
|
|
|
|
banni<6E>re, vous pouvez garder cet <20>l<EFBFBD>ment dynamique dans le contenu qui
|
|
|
|
|
est en cache. Reportez-vous <20> la documentation
|
|
|
|
|
<link linkend="language.function.insert">insert</link> pour plus de d<>tails
|
|
|
|
|
ainsi que des exemples.
|
|
|
|
|
</para>
|
|
|
|
|
<para>
|
|
|
|
|
Vous pouvez effacer tous les fichiers du cache avec la fonction <link
|
|
|
|
|
linkend="api.clear.all.cache">clear_all_cache()</link>, ou de fa<66>on
|
|
|
|
|
individuelle (ou par groupe) avec la fonction <link
|
|
|
|
|
linkend="api.clear.cache">clear_cache()</link>.
|
|
|
|
|
</para>
|
|
|
|
|
<example>
|
|
|
|
|
<title>Nettoyage du cache</title>
|
|
|
|
|
<programlisting role="php">
|
|
|
|
|
<![CDATA[
|
|
|
|
|
<?php
|
2004-04-13 11:47:32 +00:00
|
|
|
|
require('Smarty.class.php');
|
|
|
|
|
$smarty = new Smarty;
|
|
|
|
|
|
|
|
|
|
$smarty->caching = true;
|
|
|
|
|
|
|
|
|
|
// efface tous les fichiers du cache
|
|
|
|
|
$smarty->clear_all_cache();
|
|
|
|
|
|
|
|
|
|
// efface le fichier de cache du template 'index.tpl'
|
|
|
|
|
$smarty->clear_cache('index.tpl');
|
|
|
|
|
|
2004-12-26 20:05:31 +00:00
|
|
|
|
$smarty->display('index.tpl');
|
|
|
|
|
?>
|
|
|
|
|
]]>
|
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
</sect1>
|
2004-05-23 15:50:53 +00:00
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
|
Local variables:
|
|
|
|
|
mode: sgml
|
|
|
|
|
sgml-omittag:t
|
|
|
|
|
sgml-shorttag:t
|
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
|
sgml-indent-step:1
|
|
|
|
|
sgml-indent-data:t
|
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
|
sgml-parent-document:nil
|
|
|
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
|
|
|
sgml-exposed-tags:nil
|
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
|
End:
|
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
|
-->
|