Once again: Solution for {nocache} block function ?!

From: Date: Tue, 18 Feb 2003 10:34:01 +0000
Subject: Once again: Solution for {nocache} block function ?!
Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-713@lists.php.net to get a copy of this message
Hi, I just thought about how to implement a {nocache}{/nocache} block function and I had an idea ... This could also help for more advanced caching algorithms like caching of single functions or caching of variables. The caching could work the following way: http://cmsng.sourceforge.net/TemplateCaching.png - The blue path is the default behaviour of Smarty if caching is disabled. This works like in the current version. Here's the difference between a not compiled template, a precompiled and a compiled one: (The foo function is cached. The bar function is not. How to distiguish if a function or variable or what ever should be cached or not is not part of this discussion ;-) --- not compiled --- {foo blah="blub"} {bar blah="blub"} --- precompiled --- <?php echo $this->plugins["foo"] ... ?> {bar blah="blub"} --- compiled --- <?php echo $this->plugins["foo"] ... ?> <?php echo $this->plugins["bar"] ... ?> The trick is that we now have two compiled template types. The first (precompiled) one contains all the compiled syntax (PHP code) of Smarty functions that should be cached. But there are still some Smarty tags left in the code. This tags are called non-cached. If the cache is cleared Smarty executed this template. The result is another Template full of html code and still these non-cached Smarty tags. This template is called "pre-cached" because there is no php code left in the template but the non-cached Smarty tags. The second compilation step takes as input the pre-cached template instead of the completely non-compiled one. The output is a compiled template in which only the non-cached functions are php code. The cached ones are already there as html code. Now Smarty can just uses this second compiled template just like a normal one. The advantage of this method is that you can use nearly all of your existing code without any rewrites. The compiler just needs a parameter if it's the first ("pre-compiled") or second ("compiled") compile step. And it needs to distinguish between cached and non-cached functions. If it's in first compile step and a non-cached function is detected just leave it alone - don't modify it yet. If the compiler is in the second step just compile everything. The disadvantage is a performance loss if a cached template needs to be rebuild: - first get the "pre-compiled" template and execute it - compile the recently executed template again and execute again - now output the content You need to compile the template again which is slow. But normally there shouldn't be a lot of Smarty tags left in the pre-compiled template. Otherwise caching wouldn't make a sense at all. Any ideas? André

« previous php.smarty.dev (#713) next »