2004-04-13 11:47:32 +00:00
|
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
|
|
|
<!-- $Revision$ -->
|
2004-10-27 10:43:43 +00:00
|
|
|
|
<!-- EN-Revision: 1.2 Maintainer: didou Status: ready -->
|
2004-05-23 15:50:53 +00:00
|
|
|
|
<sect1 id="caching.multiple.caches">
|
|
|
|
|
<title>Caches multiples pour une seule page</title>
|
|
|
|
|
<para>
|
|
|
|
|
Vous pouvez avoir plusieurs fichiers de caches pour un m<>me appel
|
2004-10-27 10:43:43 +00:00
|
|
|
|
aux fonctions display() ou fetch(). Imaginons qu'un appel a
|
|
|
|
|
display('index.tpl') puisse avoir plusieurs r<>sultats, en fonction de
|
|
|
|
|
certaines conditions, et que
|
2004-05-23 15:50:53 +00:00
|
|
|
|
vous vouliez des fichiers de cache s<>par<61>s pour chacun d'eux. Vous
|
2004-12-26 21:12:45 +00:00
|
|
|
|
pouvez faire cel<65> en passant un identifiant de cache (cache_id) en
|
|
|
|
|
deuxi<78>me param<61>tre a l'appel de fonction.
|
2004-05-23 15:50:53 +00:00
|
|
|
|
</para>
|
|
|
|
|
<example>
|
|
|
|
|
<title>Passage d'un cache_id a display()</title>
|
2004-10-27 10:43:43 +00:00
|
|
|
|
<programlisting>
|
|
|
|
|
<![CDATA[
|
2004-04-13 11:47:32 +00:00
|
|
|
|
require('Smarty.class.php');
|
|
|
|
|
$smarty = new Smarty;
|
|
|
|
|
|
|
|
|
|
$smarty->caching = true;
|
|
|
|
|
|
|
|
|
|
$my_cache_id = $_GET['article_id'];
|
|
|
|
|
|
2004-10-27 10:43:43 +00:00
|
|
|
|
$smarty->display('index.tpl',$my_cache_id);
|
|
|
|
|
]]>
|
|
|
|
|
</programlisting>
|
2004-05-23 15:50:53 +00:00
|
|
|
|
</example>
|
|
|
|
|
<para>
|
|
|
|
|
Nous passons ci-dessus la variable $my_cache_id a display() comme
|
|
|
|
|
identifiant de cache. Pour chaque valeur distincte de $my_cache_id,
|
|
|
|
|
un fichier de cache distinct va <20>tre cr<63><72>. Dans cet exemple,
|
|
|
|
|
"article_id" a <20>t<EFBFBD> pass<73> dans l'URL et est utilis<69> en tant qu'identifiant
|
|
|
|
|
de cache.
|
|
|
|
|
</para>
|
|
|
|
|
<note>
|
|
|
|
|
<title>Note technique</title>
|
|
|
|
|
<para>
|
|
|
|
|
Soyez prudent en passant des valeurs depuis un client (navigateur Web)
|
|
|
|
|
vers Smarty (ou vers n'importe quelle application PHP). Bien que l'exemple
|
|
|
|
|
ci-dessus consistant a utiliser article_id depuis l'URL puisse paraetre
|
|
|
|
|
commode, le r<>sultat peut s'av<61>rer mauvais. L'identifiant
|
2004-12-26 21:12:45 +00:00
|
|
|
|
de cache est utilis<69> pour cr<63>er un r<>pertoire sur le syst<73>me de fichiers,
|
2004-05-23 15:50:53 +00:00
|
|
|
|
donc si l'utilisateur d<>cide de donner une tr<74>s grande valeur a article_id
|
2004-12-26 21:12:45 +00:00
|
|
|
|
ou d'<27>crire un script qui envoie des article_id de fa<66>on al<61>atoire,
|
|
|
|
|
cel<65> pourra causer des probl<62>mes cot<6F> serveur. Assurez-vous de bien
|
|
|
|
|
tester toute donn<6E>e pass<73>e en param<61>tre avant de l'utiliser. Dans cet
|
2004-05-23 15:50:53 +00:00
|
|
|
|
exemple, peut-<2D>tre savez-vous que article_id a une longueur de 10
|
2004-04-13 11:47:32 +00:00
|
|
|
|
caract<63>res, est exclusivement compos<6F> de caract<63>res alph-num<75>riques et
|
|
|
|
|
doit avoir une valeur contenue dans la base de donn<6E>es. V<>rifiez-le bien !
|
2004-05-23 15:50:53 +00:00
|
|
|
|
</para>
|
|
|
|
|
</note>
|
|
|
|
|
<para>
|
|
|
|
|
Assurez-vous de bien passer le m<>me identifiant aux fonctions
|
|
|
|
|
<link linkend="api.is.cached">is_cached()</link> et
|
2004-10-27 10:43:43 +00:00
|
|
|
|
<link linkend="api.clear.cache">clear_cache()</link>.
|
|
|
|
|
</para>
|
|
|
|
|
<example>
|
2004-12-26 20:05:31 +00:00
|
|
|
|
<title>Passer un cache_id a is_cached()</title>
|
2004-10-27 10:43:43 +00:00
|
|
|
|
<programlisting>
|
|
|
|
|
<![CDATA[
|
2004-04-13 11:47:32 +00:00
|
|
|
|
require('Smarty.class.php');
|
|
|
|
|
$smarty = new Smarty;
|
|
|
|
|
|
|
|
|
|
$smarty->caching = true;
|
|
|
|
|
|
|
|
|
|
$my_cache_id = $_GET['article_id'];
|
|
|
|
|
|
|
|
|
|
if(!$smarty->is_cached('index.tpl',$my_cache_id)) {
|
2004-12-26 20:05:31 +00:00
|
|
|
|
// pas de fichier de cache dispo, on assigne donc les variables
|
|
|
|
|
$contents = get_database_contents();
|
|
|
|
|
$smarty->assign($contents);
|
2004-04-13 11:47:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-10-27 10:43:43 +00:00
|
|
|
|
$smarty->display('index.tpl',$my_cache_id);
|
|
|
|
|
]]>
|
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
<para>
|
|
|
|
|
Vous pouvez effacer tous les fichiers de cache pour un identifiant
|
2004-12-26 21:12:45 +00:00
|
|
|
|
de cache particulier en passant null en tant que premier param<61>tre
|
|
|
|
|
<20> clear_cache().
|
2004-10-27 10:43:43 +00:00
|
|
|
|
</para>
|
|
|
|
|
<example>
|
2004-12-26 20:05:31 +00:00
|
|
|
|
<title>Effacement de tous les fichiers de cache pour un identifiant de cache particulier</title>
|
2004-10-27 10:43:43 +00:00
|
|
|
|
<programlisting>
|
|
|
|
|
<![CDATA[
|
2004-04-13 11:47:32 +00:00
|
|
|
|
require('Smarty.class.php');
|
|
|
|
|
$smarty = new Smarty;
|
|
|
|
|
|
|
|
|
|
$smarty->caching = true;
|
|
|
|
|
|
|
|
|
|
// efface tous les fichiers de cache avec "sports" comme identifiant
|
|
|
|
|
$smarty->clear_cache(null,"sports");
|
|
|
|
|
|
2004-10-27 10:43:43 +00:00
|
|
|
|
$smarty->display('index.tpl',"sports");
|
|
|
|
|
]]>
|
|
|
|
|
</programlisting>
|
|
|
|
|
</example>
|
|
|
|
|
<para>
|
2004-12-26 21:12:45 +00:00
|
|
|
|
De cette mani<6E>re, vous pouvez "grouper" vos fichiers de cache en leur
|
2004-10-27 10:43:43 +00:00
|
|
|
|
donnant le m<>me identifiant.
|
|
|
|
|
</para>
|
|
|
|
|
</sect1>
|
|
|
|
|
<!-- 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
|
|
|
|
|
-->
|