Smarty’s caching features are very interesting, but the options outlined above are still pretty inflexible. Another interesting feature is the ability to check whether a given template is already cached or not with the is_cached
function. This is important because it allows the programmer to only execute code when strictly necessary. For instance, you could decide whether to run an expensive database query or not based on whether the given template is still available on Smarty’s cache. The following example illustrates this feature:
<?php include_once(‘libs/smarty.class.php’); $smarty = new Smarty; $smarty->caching = 1; // only run this SQL query if necessary if (!$smarty->is_cached(‘templates/example4.tpl’)) { $stmt = “SELECT user_id, user_full_name FROM user WHERE user_name=’” . addslashes($username) . “’”; $result = mysql_query($stmt, $conn)...