2004-10-07 18:50:52 +00:00
|
|
|
|
<?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>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
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.
|
2004-10-07 18:50:52 +00:00
|
|
|
|
</para>
|
|
|
|
|
|
<note>
|
|
|
|
|
|
<title>Nota T<>cnica</title>
|
|
|
|
|
|
<para>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
Los archivos en el <link linkend="variable.cache.dir">$cache_dir</link> 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!
|
2004-10-07 18:50:52 +00:00
|
|
|
|
</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
|
2005-11-08 23:37:29 +00:00
|
|
|
|
caches con su propio tiempo de expiraci<63>n para configuraci<63>n
|
|
|
|
|
|
<link linkend="variable.caching">$caching</link> = 2.
|
2004-10-07 18:50:52 +00:00
|
|
|
|
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>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
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 <link linkend="variable.compile.check">$compile_check</link>
|
|
|
|
|
|
determinado false.
|
2004-10-07 18:50:52 +00:00
|
|
|
|
</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>
|
2005-11-08 23:37:29 +00:00
|
|
|
|
Si <link linkend="variable.force.compile">$force_compile</link> est<73> habilitado,
|
|
|
|
|
|
los archivos de cache siempre seran regenerados. Esto definitivamente desactiva
|
|
|
|
|
|
el caching.
|
|
|
|
|
|
<link linkend="variable.force.compile">$force_compile</link> generalmente
|
2004-10-07 18:50:52 +00:00
|
|
|
|
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
|
2005-11-08 23:37:29 +00:00
|
|
|
|
de template <link linkend="language.function.insert">{insert}</link>.
|
2004-10-07 18:50:52 +00:00
|
|
|
|
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
|
2005-11-08 23:37:29 +00:00
|
|
|
|
<link linkend="language.function.insert">{insert}</link> para detalles
|
2004-10-07 18:50:52 +00:00
|
|
|
|
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
|
|
|
|
|
|
-->
|