<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>is_cached()</title> <meta name="generator" content="DocBook XSL Stylesheets V1.75.1"> <link rel="home" href="index.html" title="Smarty Manual"> <link rel="up" href="api.functions.html" title="Chapter 13. Smarty Class Methods()"> <link rel="prev" href="api.get.template.vars.html" title="get_template_vars()"> <link rel="next" href="api.load.filter.html" title="load_filter()"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" align="center">is_cached()</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="api.get.template.vars.html">Prev</a> </td> <th width="60%" align="center">Chapter 13. Smarty Class Methods()</th> <td width="20%" align="right"> <a accesskey="n" href="api.load.filter.html">Next</a> </td> </tr> </table> <hr> </div> <div class="refentry" title="is_cached()"> <a name="api.is.cached"></a><div class="titlepage"></div> <div class="refnamediv"> <h2>Name</h2> <p>is_cached() — returns true if there is a valid cache for this template</p> </div> <div class="refsect1" title="Description"> <a name="id3102271"></a><h2>Description</h2> <code class="methodsynopsis"><span class="type">bool </span><span class="methodname">is_cached</span>(<span class="methodparam"><span class="type">string </span><span class="parameter">template</span></span>,<br> <span class="methodparam"><span class="type">string </span><span class="parameter">cache_id</span></span>,<br> <span class="methodparam"><span class="type">string </span><span class="parameter">compile_id</span></span>);</code><div class="itemizedlist"><ul class="itemizedlist" type="disc"> <li class="listitem"><p> This only works if <a class="link" href="variable.caching.html" title="$caching"> <em class="parameter"><code>$caching</code></em></a> is set to <code class="constant">TRUE</code>, see the <a class="link" href="caching.html" title="Chapter 14. Caching">caching section</a> for more info. </p></li> <li class="listitem"><p> You can also pass a <em class="parameter"><code>$cache_id</code></em> as an optional second parameter in case you want <a class="link" href="caching.multiple.caches.html" title="Multiple Caches Per Page">multiple caches</a> for the given template. </p></li> <li class="listitem"><p> You can supply a <a class="link" href="variable.compile.id.html" title="$compile_id"><em class="parameter"><code>$compile id</code></em></a> as an optional third parameter. If you omit that parameter the persistent <a class="link" href="variable.compile.id.html" title="$compile_id"> <em class="parameter"><code>$compile_id</code></em></a> is used if its set. </p></li> <li class="listitem"><p> If you do not want to pass a <em class="parameter"><code>$cache_id</code></em> but want to pass a <a class="link" href="variable.compile.id.html" title="$compile_id"> <em class="parameter"><code>$compile_id</code></em></a> you have to pass <code class="constant">NULL</code> as a <em class="parameter"><code>$cache_id</code></em>. </p></li> </ul></div> <div class="note" title="Technical Note" style="margin-left: 0.5in; margin-right: 0.5in;"> <h3 class="title">Technical Note</h3> <p> If <code class="varname">is_cached()</code> returns <code class="constant">TRUE</code> it actually loads the cached output and stores it internally. Any subsequent call to <a class="link" href="api.display.html" title="display()"><code class="varname">display()</code></a> or <a class="link" href="api.fetch.html" title="fetch()"><code class="varname">fetch()</code></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 <code class="varname">is_cached()</code> and to <a class="link" href="api.display.html" title="display()"><code class="varname">display()</code></a> in the example above. This also means calls to <a class="link" href="api.clear.cache.html" title="clear_cache()"><code class="varname">clear_cache()</code></a> and other changes of the cache-settings may have no effect after <code class="varname">is_cached()</code> returned <code class="constant">TRUE</code>. </p> </div> <div class="example"> <a name="id3102825"></a><p class="title"><b>Example 13.19. is_cached()</b></p> <div class="example-contents"><pre class="programlisting"> <?php $smarty->caching = true; if(!$smarty->is_cached('index.tpl')) { // do database calls, assign vars here } $smarty->display('index.tpl'); ?> </pre></div> </div> <br class="example-break"><div class="example"> <a name="id3102839"></a><p class="title"><b>Example 13.20. is_cached() with multiple-cache template</b></p> <div class="example-contents"><pre class="programlisting"> <?php $smarty->caching = true; if(!$smarty->is_cached('index.tpl', 'FrontPage')) { // do database calls, assign vars here } $smarty->display('index.tpl', 'FrontPage'); ?> </pre></div> </div> <br class="example-break"><p> See also <a class="link" href="api.clear.cache.html" title="clear_cache()"><code class="varname">clear_cache()</code></a>, <a class="link" href="api.clear.all.cache.html" title="clear_all_cache()"><code class="varname">clear_all_cache()</code></a>, and <a class="link" href="caching.html" title="Chapter 14. Caching">caching section</a>. </p> </div> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="api.get.template.vars.html">Prev</a> </td> <td width="20%" align="center"><a accesskey="u" href="api.functions.html">Up</a></td> <td width="40%" align="right"> <a accesskey="n" href="api.load.filter.html">Next</a> </td> </tr> <tr> <td width="40%" align="left" valign="top">get_template_vars() </td> <td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td> <td width="40%" align="right" valign="top"> load_filter()</td> </tr> </table> </div> </body> </html>