Re: [SMARTY] Cache in mysql database. Possible?

From: Date: Thu, 09 Sep 2004 19:42:00 +0000
Subject: Re: [SMARTY] Cache in mysql database. Possible?
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-11798@lists.php.net to get a copy of this message
Ajay writes: > We have a bunch of different clients so I have a bunch of different > 'template_c' folders. Upgrading smarty means that I have to do some > find/rm stuff to empty out all the compiled templates. It's no big > deal, I was just curious. > > And you're obviously right, it would be a wicked performance hit. What you can do is extend the Smarty object to automatically clear the template_c folder when the version changes. The code I use is: class CustomSmarty extends Smarty { function _CheckSmartyVersion() { $fn = $this->compile_dir.'smarty-release-'.$this->_version; if (!file_exists($fn)) { $this->clear_all_cache(); $this->clear_compiled_tpl(); touch($fn); return FALSE; } return TRUE; } function CustomSmarty() { Smarty::Smarty(); $this->_CheckSmartyVersion(); } } The advantage here is that each site can run with a different Smarty version, upgraded as and when you need to, and they all take care of the template_c issue themselves. There is a (very) small performance hit, as each page load now needs to check for the existance of the smarty-release-xx.xx file, but it's negligible except on very busy sites and certainly much faster than putting everything into a database. I've used it on production and development sites for over a year without problems (indeed with far fewer problems than I had without it). A useful "bonus" is that you can manually clear the cache any time you want by manually deleting the smarty-version-xx.xx file, and if you have several sites running different versions this is also a quick way of finding out which version is being run. -- Mark Rogers, More Solutions Ltd :: Tel: 0845 45 89 555

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