Re: [SMARTY-DEV] Once again: Solution for {nocache} block function ?!
| From: | Monte Ohrt | Date: | Tue, 18 Feb 2003 20:40:12 +0000 |
| Subject: | Re: [SMARTY-DEV] Once again: Solution for {nocache} block function ?! | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-727@lists.php.net to get a copy of this message | ||
Yep, there are a few things that have been discussed. Here's another
similar one.
We currently have three files:
1) the original template
2) compiled template
3) cached output of the template(s)
#3 is a text file that is scanned for insert tags (if there are any).
Maybe this can change to a PHP script that is interpreted by PHP, and
imbed PHP tags where uncached data should be. So for example, some
pseudo-code... foo is cached, foobar is not:
index.tpl
---------
{foo bar="blah"}
{foobar bar="blah"}
index.tpl.php
-------------
<?php smarty_function_foo("blah"); ?>
<?php smarty_function_foobar("blah"); ?>
index.tpl.cache.php
-------------------
This is output from function foo
<?php smarty_function_foobar("blah"); ?>
There are some things to get through, such as how to recognize the
cached and non-cached elements of index.tpl.php, and how to handle
multiple templates included within each other in the cache files (if
there are several templates included in a non-cached block, do they
still all go in the same cache file?)
Monte
On Tue, 2003-02-18 at 04:34, André Rabold wrote:
> 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é
--
Monte Ohrt <monte@ispi.net>