| 
									
										
										
										
											2004-04-13 11:47:32 +00:00
										 |  |  |  | <?xml version="1.0" encoding="iso-8859-1"?> | 
					
						
							|  |  |  |  | <!-- $Revision$ --> | 
					
						
							| 
									
										
										
										
											2004-05-23 15:50:53 +00:00
										 |  |  |  | <!-- EN-Revision: 1.1 Maintainer: nobody Status: partial --> | 
					
						
							|  |  |  |  | <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 | 
					
						
							|  |  |  |  |   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 | 
					
						
							|  |  |  |  |   vous vouliez des fichiers de cache s<>par<61>s pour chacun d'eux. Vous | 
					
						
							|  |  |  |  |   pouvez faire cela en passant un identifiant de cache (cache_id) en | 
					
						
							|  |  |  |  |   deuxi<78>me param<61>tre a l'appel de fonction. | 
					
						
							|  |  |  |  |  </para> | 
					
						
							|  |  |  |  |  <example> | 
					
						
							|  |  |  |  |   <title>Passage d'un cache_id a display()</title> | 
					
						
							|  |  |  |  | <programlisting> | 
					
						
							| 
									
										
										
										
											2004-04-13 11:47:32 +00:00
										 |  |  |  | require('Smarty.class.php'); | 
					
						
							|  |  |  |  | $smarty = new Smarty; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | $smarty->caching = true; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | $my_cache_id = $_GET['article_id']; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | $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 | 
					
						
							|  |  |  |  |    de cache est utilis<69> pour cr<63>er un r<>pertoire sur le syst<73>me de fichiers, | 
					
						
							|  |  |  |  |    donc si l'utilisateur d<>cide de donner une tr<74>s grande valeur a article_id | 
					
						
							|  |  |  |  |    ou d'<27>crire un script qui envoie des article_id de faton al<61>atoire, | 
					
						
							|  |  |  |  |    cela 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 | 
					
						
							|  |  |  |  |    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 | 
					
						
							|  |  |  |  |    <link linkend="api.clear.cache">clear_cache()</link>. | 
					
						
							|  |  |  |  |    </para> | 
					
						
							|  |  |  |  |    <example> | 
					
						
							|  |  |  |  |     <title>passer un  cache_id a is_cached()</title> | 
					
						
							|  |  |  |  | <programlisting> | 
					
						
							| 
									
										
										
										
											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)) { | 
					
						
							|  |  |  |  | 	// pas de fichier de cache dispo, on assigne donc les variables | 
					
						
							|  |  |  |  | 	$contents = get_database_contents(); | 
					
						
							|  |  |  |  | 	$smarty->assign($contents); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | $smarty->display('index.tpl',$my_cache_id);</programlisting> | 
					
						
							| 
									
										
										
										
											2004-05-23 15:50:53 +00:00
										 |  |  |  |    </example> | 
					
						
							|  |  |  |  |    <para> | 
					
						
							| 
									
										
										
										
											2004-04-13 11:47:32 +00:00
										 |  |  |  |     Vous pouvez effacer tous les fichiers de cache pour un identifiant | 
					
						
							|  |  |  |  |     de cache particulier en passant null en tant que premier param<61>tre | 
					
						
							|  |  |  |  |     a clear_cache(). | 
					
						
							| 
									
										
										
										
											2004-05-23 15:50:53 +00:00
										 |  |  |  |    </para> | 
					
						
							|  |  |  |  |    <example> | 
					
						
							|  |  |  |  |     <title>effacement de tous les fichiers de cache pour un identifiant de cache particulier</title> | 
					
						
							|  |  |  |  | <programlisting> | 
					
						
							| 
									
										
										
										
											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"); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | $smarty->display('index.tpl',"sports");</programlisting> | 
					
						
							| 
									
										
										
										
											2004-05-23 15:50:53 +00:00
										 |  |  |  |    </example> | 
					
						
							|  |  |  |  |    <para> | 
					
						
							| 
									
										
										
										
											2004-04-13 11:47:32 +00:00
										 |  |  |  |     De cette mani<6E>re vous pouvez "grouper" vos fichiers de cache en leur | 
					
						
							|  |  |  |  |     donnant le m<>me identifiant. | 
					
						
							| 
									
										
										
										
											2004-05-23 15:50:53 +00:00
										 |  |  |  |    </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 | 
					
						
							|  |  |  |  |   --> |