Re: [SMARTY] Caching compiled non-file templates
| From: | Marcus Bointon | Date: | Thu, 08 Sep 2005 23:34:48 +0000 |
| Subject: | Re: [SMARTY] Caching compiled non-file templates | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-13018@lists.php.net to get a copy of this message | ||
On 9 Sep 2005, at 00:05, boots wrote:
Are you not using a custom resource to retrieve the templates from the db? http://smarty.php.net/manual/en/plugins.resources.phpErm, no. At present I have this function in a Smarty subclass:
//Function takes a template in a string and compiles it through Smarty
public function compile_string_template($templatestring) {
if($templatestring == '') {
return '';
}
$this->_compile_source('string template', $templatestring, $source); //Source is passed by reference to be filled in
//Dump compiled version in output buffer
ob_start();
eval('?>' . $source);
$evaled = ob_get_contents();
ob_end_clean();
return $evaled;
}
Obviously inefficient, but functional - this code was from a smarty-general posting a couple of years ago when I originally asked about this!
Now I look at it again, the resource plugin looks promising.
I tend to store my templates along with the features in the resource that are required: a name (as a path), the template source, a timestamp (usually via an automatically updated timestamp column) and the security level.As I recall when I was setting this up originally - the problem is the path - there is no path!
Don't forget that if you are using MySQL then you ought use the MySql functions to convert to unix timestamps in your db query.I don't use timestamps anywhere now - always ISO datetimes (especially now that MySQL 4.1 uses them everywhere), but as you say, conversion is not a problem. MySQL's SQL cache is my friend ;^)
Doing this, Smarty will be able to treat your foreign templates as if they were local and will do all the right things in terms of re-compiling on an as-needed-basis.I think my question is possibly simpler (and dumber!) - when a template is in a string and the compiled results are too, where do compiled versions get cached? Still in a local templates_c folder? back in the DB? in RAM? Is that decision controllable from a plugin too? Marcus -- Marcus Bointon Synchromedia Limited: Putting you in the picture marcus@synchromedia.co.uk | http://www.synchromedia.co.uk