mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-10-31 12:21:36 +01:00 
			
		
		
		
	
		
			
	
	
		
			163 lines
		
	
	
		
			5.6 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
		
		
			
		
	
	
			163 lines
		
	
	
		
			5.6 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
|   | <?xml version="1.0" encoding="iso-8859-1"?> | |||
|  | <!-- $Revision$ --> | |||
|  |    <sect1 id="caching.setting.up"> | |||
|  |    <title>Configurando Caching</title> | |||
|  |    <para> | |||
|  |    A primeira coisa a fazer <20> habilitar o caching. Isso <20> feito pela configura<72><61>o <link | |||
|  |    linkend="variable.caching">$caching</link> = true (or 1.)      | |||
|  |    </para> | |||
|  |     <example> | |||
|  |      <title>Habilitando Caching</title> | |||
|  |      <programlisting> | |||
|  | require('Smarty.class.php'); | |||
|  | $smarty = new Smarty; | |||
|  | 
 | |||
|  | $smarty->caching = true; | |||
|  | 
 | |||
|  | $smarty->display('index.tpl');</programlisting> | |||
|  |     </example> | |||
|  | 	<para> | |||
|  | 	Com caching habilitado, a chamada para a fun<75><6E>o display('index.tpl') ir<69> trazer | |||
|  | 	o template como usual, mas tamb<6D>m | |||
|  | 	salva uma c<>pia disso para o arquivo de sa<73>da (uma c<>pia de cache) in the <link linkend="variable.cache.dir">$cache_dir</link>. | |||
|  | 	Na pr<70>xima chamada de display('index.tpl'), a c<>pia em cache ser<65> usada | |||
|  | 	ao inv<6E>s de trazer novamente o template. | |||
|  | 	</para> | |||
|  | 	<note> | |||
|  | 	<title>Notas T<>cnicas</title> | |||
|  | 	<para> | |||
|  | 	Os arquivos no $cache_dir s<>o nomeados com similaridade ao nome do arquivo de template. | |||
|  | 	Embora eles terminem com a extens<6E>o ".php", eles n<>o s<>o realmente scripts execut<75>veis de php. | |||
|  | 	N<>o edite estes arquivos! | |||
|  | 	</para> | |||
|  | 	</note> | |||
|  | 	<para> | |||
|  | 	Cada p<>gina em cache tem um per<65>odo de tempo limitado determinado por <link | |||
|  | 	linkend="variable.cache.lifetime">$cache_lifetime</link>. O padr<64>o do valor <20> | |||
|  |         3600 segundos, ou 1 hora. Ap<41>s o tempo expirar, o cache <20> regerado. | |||
|  | 	<09> poss<73>vel dar tempos individuais para caches com seu pr<70>prio tempo | |||
|  | 	de expira<72><61>o pela configura<72><61>o $caching = 2. Veja a documenta<74><61>o em <link | |||
|  | 	linkend="variable.cache.lifetime">$cache_lifetime</link> para detalhes. | |||
|  | 	</para> | |||
|  |     <example> | |||
|  |      <title>Configurando cache_lifetime por cache</title> | |||
|  |      <programlisting> | |||
|  | require('Smarty.class.php'); | |||
|  | $smarty = new Smarty; | |||
|  | 
 | |||
|  | $smarty->caching = 2; // lifetime is per cache | |||
|  | 
 | |||
|  | // set the cache_lifetime for index.tpl to 5 minutes | |||
|  | $smarty->cache_lifetime = 300; | |||
|  | $smarty->display('index.tpl'); | |||
|  | 
 | |||
|  | // set the cache_lifetime for home.tpl to 1 hour | |||
|  | $smarty->cache_lifetime = 3600; | |||
|  | $smarty->display('home.tpl'); | |||
|  | 
 | |||
|  | // NOTE: the following $cache_lifetime setting will not work when $caching = 2. | |||
|  | // The cache lifetime for home.tpl has already been set | |||
|  | // to 1 hour, and will no longer respect the value of $cache_lifetime. | |||
|  | // The home.tpl cache will still expire after 1 hour. | |||
|  | $smarty->cache_lifetime = 30; // 30 seconds | |||
|  | $smarty->display('home.tpl');</programlisting> | |||
|  |     </example> | |||
|  | 	<para> | |||
|  | 	Se <link linkend="variable.compile.check">$compile_check</link> est<73> habilitado, | |||
|  | 	cada arquivo de template e arquivo de configura<72><61>o que est<73> envolvido com o arquivo em cache | |||
|  | 	<09> checado por modifica<63><61>es. Se algum destes arquivos foi modificado desde que o <20>ltimo cache | |||
|  | 	foi gerado, o cache <20> imediatamente regerado.  | |||
|  | 	Isso <20> ligeiramente uma forma de optimiza<7A><61>o de performance de overhead, deixe $compile_check setado para false. | |||
|  | 	</para> | |||
|  |     <example> | |||
|  |      <title>Habilitando $compile_check</title> | |||
|  |      <programlisting> | |||
|  | require('Smarty.class.php'); | |||
|  | $smarty = new Smarty; | |||
|  | 
 | |||
|  | $smarty->caching = true; | |||
|  | $smarty->compile_check = true; | |||
|  | 
 | |||
|  | $smarty->display('index.tpl');</programlisting> | |||
|  | 	</example> | |||
|  | 	<para> | |||
|  | 	Se <link linkend="variable.force.compile">$force_compile</link> est<73> habilitado, | |||
|  | 	os arquivos de cache ir<69>o sempre ser regerados. Isso <20> efetivamente desativar caching. | |||
|  |         $force_compile <20> usualmente para prop<6F>sitos de debug somente, um caminho mais | |||
|  | 	eficiente de desativar caching <20> setar o <link | |||
|  | 	linkend="variable.caching">$caching</link> = false (ou 0.) | |||
|  | 	</para> | |||
|  | 	<para> | |||
|  | 	A fun<75><6E>o <link linkend="api.is.cached">is_cached()</link>  | |||
|  | 	pode ser usada para testar se um template tem um cache v<>lido ou n<>o. | |||
|  | 	Se voc<6F> tem um template com cache que requer alguma coisa como um retorno do banco de dados, | |||
|  | 	voc<6F> pode usar isso para pular este processo. | |||
|  | 	</para> | |||
|  |     <example> | |||
|  |      <title>Usando is_cached()</title> | |||
|  |      <programlisting> | |||
|  | require('Smarty.class.php'); | |||
|  | $smarty = new Smarty; | |||
|  | 
 | |||
|  | $smarty->caching = true; | |||
|  | 
 | |||
|  | if(!$smarty->is_cached('index.tpl')) { | |||
|  | 	// No cache available, do variable assignments here. | |||
|  | 	$contents = get_database_contents(); | |||
|  | 	$smarty->assign($contents); | |||
|  | } | |||
|  | 
 | |||
|  | $smarty->display('index.tpl');</programlisting> | |||
|  |     </example> | |||
|  | 	<para> | |||
|  | 	Voc<6F> pode deixar partes da sua p<>gina din<69>mica com a fun<75><6E>o de template <link | |||
|  | 	linkend="language.function.insert">insert</link>. | |||
|  | 	Vamos dizer que sua p<>gina inteira pode ter cache exceto para um banner que <20> | |||
|  | 	mostrado abaixo do lado direito da sua p<>gina. Usando uma fun<75><6E>o insert para o banner, | |||
|  | 	voc<6F> pode deixar esse elemento din<69>mico dentro do conte<74>do de cache. Veja a documenta<74><61>o | |||
|  | 	em <link linkend="language.function.insert">insert</link> para  | |||
|  | 	detalhes e exemplos. | |||
|  | 	</para> | |||
|  | 	<para> | |||
|  | 	Voc<6F> pode limpar todos os arquivos de cache com a fun<75><6E>o <link | |||
|  | 	linkend="api.clear.all.cache">clear_all_cache()</link>, ou | |||
|  | 	arquivos de cache individuais (ou grupos) com a fun<75><6E>o <link | |||
|  | 	linkend="api.clear.cache">clear_cache()</link>.	 | |||
|  | 	</para> | |||
|  |     <example> | |||
|  |      <title>Limpando o cache</title> | |||
|  |      <programlisting> | |||
|  | require('Smarty.class.php'); | |||
|  | $smarty = new Smarty; | |||
|  | 
 | |||
|  | $smarty->caching = true; | |||
|  | 
 | |||
|  | // clear out all cache files | |||
|  | $smarty->clear_all_cache(); | |||
|  | 
 | |||
|  | // clear only cache for index.tpl | |||
|  | $smarty->clear_cache('index.tpl'); | |||
|  | 
 | |||
|  | $smarty->display('index.tpl');</programlisting> | |||
|  |     </example> | |||
|  | </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 | |||
|  | --> |