Re: [SMARTY-DEV] First step to solve {nocache} {/nocache} problematic
| From: | Monte Ohrt | Date: | Wed, 22 Jan 2003 16:01:20 +0000 |
| Subject: | Re: [SMARTY-DEV] First step to solve {nocache} {/nocache} problematic | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-589@lists.php.net to get a copy of this message | ||
Actually caching is next on the to-do list, after we (hopefully :-) get
through the object support. The Smarty compiling engine has already gone
through extensive cleanup in the regex area. The next step will be to
pipeline the entire compilation/execution process so it will be easier
to manage plug-in functionality at any given point. This may involve a
change in the way the template cache works, such as parsed vs. executed
cache files.
But before that, we could work on the conceptual level of how the cache
should work. Currently there is no syntax in the templates that deal
with cache. Do we want to introduce that? This is another designer vs.
programmer issue. Does the designer care what portions of a template are
cached or not cached? Should cached portions of a page be included,
imbedded or both? Maybe it would be helpful to designate custom
functions as cached or non-cached at registration time, so {myFunc
foo="bar"} may or may not get cached depending on how it was registered.
Monte
On Wed, 2003-01-22 at 02:29, André Rabold wrote:
> Hi folks,
>
> I have tried to solve the {nocache} {/nocache} problematic. Many users
> requested a block
> function which's content gets never cached. This would make template
> development using
> caching a lot easier than splitting them in hundreds of pieces and then to
> use {insert} tags.
>
> At the end of this document you find two patches. DO NOT USE THEM!
> Using these patches Smarty will recognize {nocache} ... {/nocache} block
> tags. They will be compiled into <?php /* NOCACHE */ eval(...) ?>.
> Even in the cached template these special PHP tags will remain. While
> displaying the cached templated the evals get executed. This already works
> very well.
>
> One problem is still to solve: At runtime (of the cached templated) I have
> no information about needed plugins so all function calls ({foo bar="blah"})
> will fail.
> So we need a functionality which inserts into the cached template some
> informations about needed plugins. This is still to do. There are also some
> other bugs I think. But the good thing is that the new {nocache} tag doesn't
> break any current Smarty syntax.
>
> What do you think? Is this a good approach?
>
> Any comments?
> André
>
>
>
> Index: Smarty.class.php
> ===================================================================
> RCS file: /repository/smarty/Smarty.class.php,v
> retrieving revision 1.329
> diff -r1.329 Smarty.class.php
> 648a649,654
> > if (preg_match_all('/\<\?php \/\* NOCACHE \*\/ echo eval\("(.*?)"\);
> \?>/si', $_smarty_results, $matches)) {
> > foreach ($matches[1] as $key => $code) {
> > $matches[1][$key] = eval($code);
> > }
> > $_smarty_results = str_replace($matches[0], $matches[1],
> $_smarty_results);
> > }
> 1412a1419,1439
> > }
> > }
> >
> > /*======================================================================*\
> > Function: _run_nocache_handler
> > Purpose: Handle nocache tags
> > \*======================================================================*/
> > function _run_nocache_handler($args, $content)
> > {
> > if ($this->debugging) {
> > $debug_start_time = $this->_get_microtime();
> > }
> >
> > $ques="?";
> > $php_open="<${ques}php";
> > $php_close="${ques}>";
> > if ($this->caching) {
> > $evalcode = $php_close.$content.$php_open." ";
> > return "$php_open /* NOCACHE */ echo eval(\"".$evalcode."\");
> > $php_close";
> > } else {
> > return eval($php_close.$content.$php_open." ");
>
>
>
>
> Index: Smarty_Compiler.class.php
> ===================================================================
> RCS file: /repository/smarty/Smarty_Compiler.class.php,v
> retrieving revision 1.148
> diff -r1.148 Smarty_Compiler.class.php
> 269c269,274
> < $compiled_tags[] = $this->_compile_tag($template_tags[$i]);
> ---
> > if ($this->_nocache_tag && $template_tags[$i] != "/nocache") {
> > $compiled_tags[] =
> addcslashes($this->_compile_tag($template_tags[$i]),"$\\");
> > }
> > else {
> > $compiled_tags[] = $this->_compile_tag($template_tags[$i]);
> > }
> 443a449,454
> > case 'nocache':
> > return $this->_compile_nocache_starttag($tag_args);
> >
> > case '/nocache':
> > return $this->_compile_nocache_endtag($tag_args);
> >
> 664a676,696
> > /*======================================================================*\
> > Function: _compile_nocache_starttag
> > Purpose: Compile {nocache}...{/nocache} tag
> > \*======================================================================*/
> > function _compile_nocache_starttag($tag_args)
> > {
> > $this->_nocache_tag = true;
> > return "<?php \$_NOCACHE_CONTENT = <<<NOCACHE\n";
> > }
> >
> > /*======================================================================*\
> > Function: _compile_nocache_starttag
> > Purpose: Compile {nocache}...{/nocache} tag
> > \*======================================================================*/
> > function _compile_nocache_endtag($tag_args)
> > {
> > $this->_nocache_tag = false;
> > $content = "\nNOCACHE;\n".
> > "echo \$this->_run_nocache_handler(array(".implode(', ',
> (array)$arg_list)."),\$_NOCACHE_CONTENT); ?>\n";
> > return $content;
> > }
--
Monte Ohrt <monte@ispi.net>