mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-11-03 22:01:36 +01:00 
			
		
		
		
	
		
			
	
	
		
			200 lines
		
	
	
		
			6.1 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
		
		
			
		
	
	
			200 lines
		
	
	
		
			6.1 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
| 
								 | 
							
								<?xml version="1.0" encoding="iso-8859-1"?>
							 | 
						|||
| 
								 | 
							
								<!-- $Revision$ -->
							 | 
						|||
| 
								 | 
							
								  <sect1 id="caching.setting.up">
							 | 
						|||
| 
								 | 
							
								   <title>Configurando el Cache</title>
							 | 
						|||
| 
								 | 
							
								   <para>
							 | 
						|||
| 
								 | 
							
								    Lo primero que se tiene que hacer es habilitar el cache. esto es configurar
							 | 
						|||
| 
								 | 
							
								    <link linkend="variable.caching">$caching</link> = true (o 1.)
							 | 
						|||
| 
								 | 
							
								   </para>
							 | 
						|||
| 
								 | 
							
								   <example>
							 | 
						|||
| 
								 | 
							
								    <title>Habilitando Cache</title>
							 | 
						|||
| 
								 | 
							
								    <programlisting role="php">
							 | 
						|||
| 
								 | 
							
								<![CDATA[
							 | 
						|||
| 
								 | 
							
								<?php
							 | 
						|||
| 
								 | 
							
								require('Smarty.class.php');
							 | 
						|||
| 
								 | 
							
								$smarty = new Smarty;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								$smarty->caching = true;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								$smarty->display('index.tpl');
							 | 
						|||
| 
								 | 
							
								?>
							 | 
						|||
| 
								 | 
							
								]]>
							 | 
						|||
| 
								 | 
							
								    </programlisting>
							 | 
						|||
| 
								 | 
							
								   </example>
							 | 
						|||
| 
								 | 
							
								   <para>
							 | 
						|||
| 
								 | 
							
								     Con el caching habilitado, la llamada a la funci<63>n 
							 | 
						|||
| 
								 | 
							
								     display('index.tpl') traera el template como siempre, 
							 | 
						|||
| 
								 | 
							
								     pero tambi<62>n salvara una copia en el archivo de salida
							 | 
						|||
| 
								 | 
							
								     (una copia de cache) en el 
							 | 
						|||
| 
								 | 
							
								     <link linkend="variable.cache.dir">$cache_dir</link>.
							 | 
						|||
| 
								 | 
							
								     En la proxima llamada de display('index.tpl'), la copia 
							 | 
						|||
| 
								 | 
							
								     en cache sera usada en vez de traer nuevamente el template.
							 | 
						|||
| 
								 | 
							
								   </para>
							 | 
						|||
| 
								 | 
							
								   <note>
							 | 
						|||
| 
								 | 
							
								    <title>Nota T<>cnica</title>
							 | 
						|||
| 
								 | 
							
								    <para>
							 | 
						|||
| 
								 | 
							
								      Los archivos en el $cache_dir son nombrados similarmente al 
							 | 
						|||
| 
								 | 
							
								      nombre del archivo de template.
							 | 
						|||
| 
								 | 
							
								      Aunque ellos tengan una extensi<73>n ".php", ellos no son realmente
							 | 
						|||
| 
								 | 
							
								      scripts ejecutables de php. No edite estos archivos!
							 | 
						|||
| 
								 | 
							
								    </para>
							 | 
						|||
| 
								 | 
							
								   </note>
							 | 
						|||
| 
								 | 
							
								   <para>
							 | 
						|||
| 
								 | 
							
								    Cada pagina en cache tiene un periodo de tiempo limitado determinado por
							 | 
						|||
| 
								 | 
							
								    <link linkend="variable.cache.lifetime">$cache_lifetime</link>.
							 | 
						|||
| 
								 | 
							
								    El default del valor es 3600 segundos, o 1 hora. Despu<70>s de este tiempo 
							 | 
						|||
| 
								 | 
							
								    expira, el cache es regenerado. Es posible dar tiempos individuales para 
							 | 
						|||
| 
								 | 
							
								    caches con su propio tiempo de expiraci<63>n para configuraci<63>n $caching = 2. 
							 | 
						|||
| 
								 | 
							
								    Vea la documentaci<63>n en 
							 | 
						|||
| 
								 | 
							
								    <link linkend="variable.cache.lifetime">$cache_lifetime</link>
							 | 
						|||
| 
								 | 
							
								    para mas detalles.
							 | 
						|||
| 
								 | 
							
								   </para>
							 | 
						|||
| 
								 | 
							
								   <example>
							 | 
						|||
| 
								 | 
							
								    <title>Configurando cache_lifetime por cache</title>
							 | 
						|||
| 
								 | 
							
								    <programlisting role="php">
							 | 
						|||
| 
								 | 
							
								<![CDATA[
							 | 
						|||
| 
								 | 
							
								<?php
							 | 
						|||
| 
								 | 
							
								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>
							 | 
						|||
| 
								 | 
							
								    Si <link linkend="variable.compile.check">$compile_check</link> est<73>
							 | 
						|||
| 
								 | 
							
								    habilitado, cada archivo de template y archivo de configuraci<63>n que
							 | 
						|||
| 
								 | 
							
								    est<73> involucrado con el archivo en cache es checado por modificadores.
							 | 
						|||
| 
								 | 
							
								    Si alguno de estos archivos fue modificado desde que el ultimo cache 
							 | 
						|||
| 
								 | 
							
								    fue generado, el cache es regenerado inmediatamente. Esto es una forma 
							 | 
						|||
| 
								 | 
							
								    de optimizar ligeramente el rendimiento de las cabeceras, dejar
							 | 
						|||
| 
								 | 
							
								    $compile_check determinado false.
							 | 
						|||
| 
								 | 
							
								   </para>
							 | 
						|||
| 
								 | 
							
								   <example>
							 | 
						|||
| 
								 | 
							
								    <title>Habilitando $compile_check</title>
							 | 
						|||
| 
								 | 
							
								    <programlisting role="php">
							 | 
						|||
| 
								 | 
							
								<![CDATA[
							 | 
						|||
| 
								 | 
							
								<?php
							 | 
						|||
| 
								 | 
							
								require('Smarty.class.php');
							 | 
						|||
| 
								 | 
							
								$smarty = new Smarty;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								$smarty->caching = true;
							 | 
						|||
| 
								 | 
							
								$smarty->compile_check = true;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								$smarty->display('index.tpl');
							 | 
						|||
| 
								 | 
							
								?>
							 | 
						|||
| 
								 | 
							
								]]>
							 | 
						|||
| 
								 | 
							
								    </programlisting>
							 | 
						|||
| 
								 | 
							
								   </example>
							 | 
						|||
| 
								 | 
							
								   <para>
							 | 
						|||
| 
								 | 
							
								    Si <link linkend="variable.force.compile">$force_compile</link> est<73>
							 | 
						|||
| 
								 | 
							
								    habilitado, los archivos de cache siempre seran regenerados. 
							 | 
						|||
| 
								 | 
							
								    Esto definitivamente desactiva el caching. $force_compile generalmente 
							 | 
						|||
| 
								 | 
							
								    es usado para propositos de debug solamente, una forma mas eficiente 
							 | 
						|||
| 
								 | 
							
								    de desactivar el caching es asignando
							 | 
						|||
| 
								 | 
							
								    <link linkend="variable.caching">$caching</link> = false (<28> 0.)
							 | 
						|||
| 
								 | 
							
								   </para>
							 | 
						|||
| 
								 | 
							
								   <para>
							 | 
						|||
| 
								 | 
							
								    La funci<63>n <link linkend="api.is.cached">is_cached()</link> puede ser 
							 | 
						|||
| 
								 | 
							
								    usada para testar si un template tiene un cache valido o no. Si usted 
							 | 
						|||
| 
								 | 
							
								    tiene un template con cache que requiera alguna cosa como un retorno 
							 | 
						|||
| 
								 | 
							
								    de base de datos, usted puede usar esto para saltar este proceso.
							 | 
						|||
| 
								 | 
							
								   </para>
							 | 
						|||
| 
								 | 
							
								   <example>
							 | 
						|||
| 
								 | 
							
								    <title>Usando is_cached()</title>
							 | 
						|||
| 
								 | 
							
								    <programlisting role="php">
							 | 
						|||
| 
								 | 
							
								<![CDATA[
							 | 
						|||
| 
								 | 
							
								<?php
							 | 
						|||
| 
								 | 
							
								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>
							 | 
						|||
| 
								 | 
							
								    Usted puede guardar partes de su pagina din<69>mica con la funci<63>n
							 | 
						|||
| 
								 | 
							
								    de template <link linkend="language.function.insert">insert</link>.
							 | 
						|||
| 
								 | 
							
								    Vamos a decir que su pagina entera puede tener cache excepto para un
							 | 
						|||
| 
								 | 
							
								    banner que es mostrado abajo del lado derecho de su pagina. Usando 
							 | 
						|||
| 
								 | 
							
								    la funci<63>n insert para el banner, usted puede guardar ese elemento 
							 | 
						|||
| 
								 | 
							
								    din<69>mico dentro de un contenido de cache. Vea la documentaci<63>n en 
							 | 
						|||
| 
								 | 
							
								    <link linkend="language.function.insert">insert</link> para detalles 
							 | 
						|||
| 
								 | 
							
								    y ejemplos.
							 | 
						|||
| 
								 | 
							
								   </para>
							 | 
						|||
| 
								 | 
							
								   <para>
							 | 
						|||
| 
								 | 
							
								    Usted puede limpiar todos los archivos de cache con la funci<63>n
							 | 
						|||
| 
								 | 
							
								    <link linkend="api.clear.all.cache">clear_all_cache()</link>,
							 | 
						|||
| 
								 | 
							
								    los archivos de cache individuales (o grupos) con la funci<63>n 
							 | 
						|||
| 
								 | 
							
								    <link linkend="api.clear.cache">clear_cache()</link>.
							 | 
						|||
| 
								 | 
							
								   </para>
							 | 
						|||
| 
								 | 
							
								   <example>
							 | 
						|||
| 
								 | 
							
								    <title>Limpiando el cache</title>
							 | 
						|||
| 
								 | 
							
								    <programlisting role="php">
							 | 
						|||
| 
								 | 
							
								<![CDATA[
							 | 
						|||
| 
								 | 
							
								<?php
							 | 
						|||
| 
								 | 
							
								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
							 | 
						|||
| 
								 | 
							
								-->
							 |