What's coming up in Smarty 1.3.0

From: Date: Wed, 07 Feb 2001 16:24:58 +0000
Subject: What's coming up in Smarty 1.3.0
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-79@lists.php.net to get a copy of this message
We've been working hard the last week getting the 1.3.0 release of Smarty completed. Some of the changes include small bug fixes and under-the-hood performance tune-ups. But the main focus of the 1.3.0 release is template caching. Smarty caches the template output to a file, where it can be retrieved and displayed instead of reparsing the template each time. Smarty's caching technique allows dynamic elements in your cache with the use of the {insert ...} tag. Any content created by {insert ...} is not cached, but ran dynamically on each invocation. This is handy for things like banners, polls, search results, etc... any content you wouldn't want cached. Careful consideration has been taken to structure the cache files in such a way that file access will remain quick, even with potentially thousands of cache files (i.e. we don't dump all the files in one directory.) Here are the new vars for caching: var $caching = false; // whether to use caching or not. true/false var $cache_dir = './cache'; // name of directory for template cache var $cache_lifetime = 3600; // number of seconds cached content will persist. // 0 = never expires. default is one hour (3600) And new API calls: clear_cache(); // clearing a single cache clear_all_cache(); // clear all caches is_cached() // check for existance of valid cache Here is how you might use caching in your scripts: $smarty = new Smarty; $smarty->caching=true; if(!$smarty->is_cached("index.tpl")) { // here you do database queries, var assignments, etc. // needed for initial generation of template, // but not needed for cache } $smarty->display("index.tpl"); There is also a way to create multiple caches per template. Let's say you have a template used to display newspaper articles. You wouldn't want to use the same cache for each article, so you pass an optional ID parameter to distinguish the cache: $smarty = new Smarty; $smarty->caching=true; if(!$smarty->is_cached("index.tpl","ARTID12345")) { // here you do database queries, var assignments, etc. // needed for initial generation of template, // but not needed for cache } $smarty->display("index.tpl","ARTID12345"); If you want separate caches per template but don't want to deal with making IDs, you could use the URL as an ID like this: $smarty->display("index.tpl",$PHP_SELF); Caveats: * We are still working on methods to automatically clean up stale cache files. * If you compile your templates with caching on and then turn caching off, you must recompile all your templates that use the insert tag. Otherwise you get junk in your templates where the insert tag should be. Is this really a problem? thoughts, ideas, questions? Monte

« previous php.smarty.general (#79) next »