<HTML ><HEAD ><TITLE >is_cached()</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Smarty Manual" HREF="index.html"><LINK REL="UP" TITLE="Smarty Class Methods()" HREF="api.functions.html"><LINK REL="PREVIOUS" TITLE="get_template_vars()" HREF="api.get.template.vars.html"><LINK REL="NEXT" TITLE="load_filter()" HREF="api.load.filter.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Smarty Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="api.get.template.vars.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="api.load.filter.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="api.is.cached" ></A >is_cached()</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN5946" ></A >is_cached() -- returns true if there is a valid cache for this template</DIV ><DIV CLASS="refsect1" ><A NAME="AEN5949" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >is_cached</B > ( string template [, string cache_id [, string compile_id]])<BR ></BR ><P ></P ><UL ><LI ><P > This only works if <A HREF="variable.caching.html" > <TT CLASS="parameter" ><I >$caching</I ></TT ></A > is set to <TT CLASS="constant" >TRUE</TT >, see the <A HREF="caching.html" >caching section</A > for more info. </P ></LI ><LI ><P > You can also pass a <TT CLASS="parameter" ><I >$cache_id</I ></TT > as an optional second parameter in case you want <A HREF="caching.multiple.caches.html" >multiple caches</A > for the given template. </P ></LI ><LI ><P > You can supply a <A HREF="variable.compile.id.html" ><TT CLASS="parameter" ><I >$compile id</I ></TT ></A > as an optional third parameter. If you omit that parameter the persistent <A HREF="variable.compile.id.html" > <TT CLASS="parameter" ><I >$compile_id</I ></TT ></A > is used if its set. </P ></LI ><LI ><P > If you do not want to pass a <TT CLASS="parameter" ><I >$cache_id</I ></TT > but want to pass a <A HREF="variable.compile.id.html" > <TT CLASS="parameter" ><I >$compile_id</I ></TT ></A > you have to pass <TT CLASS="constant" >NULL</TT > as a <TT CLASS="parameter" ><I >$cache_id</I ></TT >. </P ></LI ></UL ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Technical Note: </B > If <TT CLASS="varname" >is_cached()</TT > returns <TT CLASS="constant" >TRUE</TT > it actually loads the cached output and stores it internally. Any subsequent call to <A HREF="api.display.html" ><TT CLASS="varname" >display()</TT ></A > or <A HREF="api.fetch.html" ><TT CLASS="varname" >fetch()</TT ></A > will return this internally stored output and does not try to reload the cache file. This prevents a race condition that may occur when a second process clears the cache between the calls to <TT CLASS="varname" >is_cached()</TT > and to <A HREF="api.display.html" ><TT CLASS="varname" >display()</TT ></A > in the example above. This also means calls to <A HREF="api.clear.cache.html" ><TT CLASS="varname" >clear_cache()</TT ></A > and other changes of the cache-settings may have no effect after <TT CLASS="varname" >is_cached()</TT > returned <TT CLASS="constant" >TRUE</TT >. </P ></BLOCKQUOTE ></DIV ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6003" ></A ><P ><B >Example 13-1. is_cached()</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$smarty</span><span style="color: #007700">-></span><span style="color: #0000BB">caching </span><span style="color: #007700">= </span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /><br />if(!</span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-></span><span style="color: #0000BB">is_cached</span><span style="color: #007700">(</span><span style="color: #DD0000">'index.tpl'</span><span style="color: #007700">)) {<br /></span><span style="color: #FF8000">// do database calls, assign vars here<br /></span><span style="color: #007700">}<br /><br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-></span><span style="color: #0000BB">display</span><span style="color: #007700">(</span><span style="color: #DD0000">'index.tpl'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN6006" ></A ><P ><B >Example 13-2. is_cached() with multiple-cache template</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$smarty</span><span style="color: #007700">-></span><span style="color: #0000BB">caching </span><span style="color: #007700">= </span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /><br />if(!</span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-></span><span style="color: #0000BB">is_cached</span><span style="color: #007700">(</span><span style="color: #DD0000">'index.tpl'</span><span style="color: #007700">, </span><span style="color: #DD0000">'FrontPage'</span><span style="color: #007700">)) {<br /> </span><span style="color: #FF8000">// do database calls, assign vars here<br /></span><span style="color: #007700">}<br /><br /></span><span style="color: #0000BB">$smarty</span><span style="color: #007700">-></span><span style="color: #0000BB">display</span><span style="color: #007700">(</span><span style="color: #DD0000">'index.tpl'</span><span style="color: #007700">, </span><span style="color: #DD0000">'FrontPage'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P > See also <A HREF="api.clear.cache.html" ><TT CLASS="varname" >clear_cache()</TT ></A >, <A HREF="api.clear.all.cache.html" ><TT CLASS="varname" >clear_all_cache()</TT ></A >, and <A HREF="caching.html" >caching section</A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="api.get.template.vars.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="api.load.filter.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >get_template_vars()</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="api.functions.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >load_filter()</TD ></TR ></TABLE ></DIV ></BODY ></HTML >