mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-10-31 04:11:37 +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 é habilitar o caching. Isso é feito pela configuraçã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ção display('index.tpl') irá trazer
 | |
| 	o template como usual, mas também
 | |
| 	salva uma cópia disso para o arquivo de saída (uma cópia de cache) in the <link linkend="variable.cache.dir">$cache_dir</link>.
 | |
| 	Na próxima chamada de display('index.tpl'), a cópia em cache será usada
 | |
| 	ao invé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ão ".php", eles não são realmente scripts executáveis de php.
 | |
| 	Não edite estes arquivos!
 | |
| 	</para>
 | |
| 	</note>
 | |
| 	<para>
 | |
| 	Cada página em cache tem um período de tempo limitado determinado por <link
 | |
| 	linkend="variable.cache.lifetime">$cache_lifetime</link>. O padrão do valor é
 | |
|         3600 segundos, ou 1 hora. Após o tempo expirar, o cache é regerado.
 | |
| 	É possível dar tempos individuais para caches com seu próprio tempo
 | |
| 	de expiração pela configuração $caching = 2. Veja a documentaçã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á habilitado,
 | |
| 	cada arquivo de template e arquivo de configuração que está envolvido com o arquivo em cache
 | |
| 	é checado por modificações. Se algum destes arquivos foi modificado desde que o último cache
 | |
| 	foi gerado, o cache é imediatamente regerado. 
 | |
| 	Isso é ligeiramente uma forma de optimizaçã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á habilitado,
 | |
| 	os arquivos de cache irão sempre ser regerados. Isso é efetivamente desativar caching.
 | |
|         $force_compile é usualmente para propósitos de debug somente, um caminho mais
 | |
| 	eficiente de desativar caching é setar o <link
 | |
| 	linkend="variable.caching">$caching</link> = false (ou 0.)
 | |
| 	</para>
 | |
| 	<para>
 | |
| 	A funçã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ê tem um template com cache que requer alguma coisa como um retorno do banco de dados,
 | |
| 	você 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ê pode deixar partes da sua página dinâmica com a funçã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 é
 | |
| 	mostrado abaixo do lado direito da sua página. Usando uma função insert para o banner,
 | |
| 	você pode deixar esse elemento dinâmico dentro do conteúdo de cache. Veja a documentação
 | |
| 	em <link linkend="language.function.insert">insert</link> para 
 | |
| 	detalhes e exemplos.
 | |
| 	</para>
 | |
| 	<para>
 | |
| 	Você pode limpar todos os arquivos de cache com a função <link
 | |
| 	linkend="api.clear.all.cache">clear_all_cache()</link>, ou
 | |
| 	arquivos de cache individuais (ou grupos) com a funçã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
 | |
| --> |