mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-05 14:51:37 +01:00
128 lines
4.2 KiB
XML
128 lines
4.2 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 1.7 Maintainer: yannick Status: ready -->
|
|
|
|
<refentry id="api.is.cached">
|
|
<refnamediv>
|
|
<refname>is_cached()</refname>
|
|
<refpurpose>Retourne &true; s'il y a un fichier de cache valide pour ce template</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<methodsynopsis>
|
|
<type>bool</type><methodname>is_cached</methodname>
|
|
<methodparam><type>string</type><parameter>template</parameter></methodparam>
|
|
<methodparam choice="opt"><type>string</type><parameter>cache_id</parameter></methodparam>
|
|
<methodparam choice="opt"><type>string</type><parameter>compile_id</parameter></methodparam>
|
|
</methodsynopsis>
|
|
|
|
<itemizedlist>
|
|
<listitem><para>
|
|
Celà fonctionne seulement si <link linkend="variable.caching">
|
|
<parameter>$caching</parameter></link> est défini à &true;, voir aussi la
|
|
<link linkend="caching">section sur le cache</link> pour plus d'informations.
|
|
</para></listitem>
|
|
|
|
<listitem><para>
|
|
Vous pouvez aussi passer en second paramètre un identifiant
|
|
de <parameter>$cache_id</parameter> au cas où vous voudriez
|
|
<link linkend="caching.multiple.caches">plusieurs
|
|
fichiers</link> de cache pour ce template.
|
|
</para></listitem>
|
|
|
|
<listitem><para>
|
|
Vous pouvez donner un
|
|
<link linkend="variable.compile.id"><parameter>$compile id</parameter></link>
|
|
en tant que troisième paramètre. Si vous ne spécifiez pas ce paramètre, le
|
|
<link linkend="variable.compile.id">
|
|
<parameter>$compile_id</parameter></link> persistant sera utilisé.
|
|
</para></listitem>
|
|
|
|
<listitem><para>
|
|
Si vous ne voulez pas passer un <parameter>$cache_id</parameter> mais plutôt un
|
|
<link linkend="variable.compile.id">
|
|
<parameter>$compile_id</parameter></link>, vous devez passer
|
|
&null; en tant que <parameter>$cache_id</parameter>.
|
|
</para></listitem>
|
|
</itemizedlist>
|
|
|
|
<note>
|
|
<title>Note technique</title>
|
|
<para>
|
|
Si <varname>is_cached()</varname> retourne &true;, il charge en fait le cache existant et
|
|
le stocke en interne. Tout appel supplémentaire à
|
|
<link linkend="api.display"><varname>display()</varname></link> ou
|
|
<link linkend="api.fetch"><varname>fetch()</varname></link> retournera ce
|
|
contenu stocké en interne
|
|
sans tenter de recharger le fichier en cache. Celà évite des problématiques d'accès concurents,
|
|
lorsqu'un second processus efface le cache entre l'appel de
|
|
<varname>is_cached()</varname> et l'appel à
|
|
<link linkend="api.display"><varname>display()</varname></link>
|
|
comme dans l'un de nos exemples ci-dessus. Celà signifie également que les appels à
|
|
<link linkend="api.clear.cache"><varname>clear_cache()</varname></link>
|
|
et les changements de paramètres du cache peuvent n'avoir aucun effet alors que
|
|
<varname>is_cached()</varname> a retourné &true;.
|
|
</para>
|
|
</note>
|
|
|
|
<example>
|
|
<title>Exemple avec is_cached()</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$smarty->caching = true;
|
|
|
|
if(!$smarty->is_cached('index.tpl')) {
|
|
//aucun appel à la base de donnée
|
|
}
|
|
|
|
$smarty->display('index.tpl');
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<example>
|
|
<title>Exemple avec is_cached() et plusieurs templates</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$smarty->caching = true;
|
|
|
|
if(!$smarty->is_cached('index.tpl', 'FrontPage')) {
|
|
//appel de la base de données, assignation des variables
|
|
}
|
|
|
|
$smarty->display('index.tpl', 'FrontPage');
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<para>
|
|
Voir aussi
|
|
<link linkend="api.clear.cache"><varname>clear_cache()</varname></link>,
|
|
<link linkend="api.clear.all.cache"><varname>clear_all_cache()</varname></link> et
|
|
la <link linkend="caching">section sur le cache</link>.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- 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
|
|
--> |