Re: [SMARTY-DEV] First step to solve {nocache} {/nocache}problematic
| From: | Andr� Rabold | Date: | Wed, 22 Jan 2003 16:26:47 +0000 |
| Subject: | Re: [SMARTY-DEV] First step to solve {nocache} {/nocache}problematic | ||
| References: | 1 2 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-590@lists.php.net to get a copy of this message | ||
Yeah, that's right, Monte.
> Does the designer care what portions of a template are
> cached or not cached?
Doesn't the designer already have this possibility? He
must know what the {insert} function is for or he won't use it at
all. So he always need to know if his template will be cached
and what portions shouldn't be cached. Am I wrong?
Btw: I'm not using caching at all for now... ;-)
I have an example why {nocache} could be very useful:
I have a template showing a table. In each row another data
record is shown. Behind each row there are three buttons:
view / edit / delete. Depending on the current access level
I want to display or hide one or all of these buttons. E.g.:
{if $canEdit}
<a href="...">edit</a>
{/if}
All of the content can and should be cached for performance
reasons. But not the three buttons behind each line. I could
use different cache ids for different access levels but in this
case very very much cached templates would be created :-(
So a {nocache}{/nocache} function surrounding the above
code would be a good solution in my eyes.
If the designed shouldn't care / is not allowed to care about
caching, how would a good solution look like? I have already
thought about using {insert} tags but I'm not quite happy with
it. Perhaps anyone has an idea?
> Should cached portions of a page be included,
> imbedded or both?
I'm not sure what you mean?!
> 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.
This sounds quite useful. If the programmer desides if a function can be
cached
or not the designer doesn't need to deside anymore.
But then also a block function which won't be cached would be one of the
first requests. This won't be possible easily because of the question if all
included function of the block plugin should should be cached or not:
{myNocachedBlockFunction}
{* should this be cached or not ??? *}
{/myNocachedBlockFunction}
If the content of the block function is NOT cached then it would be the same
as the idea of a {nocache}{/nocache} block.
"Monte Ohrt" <monte@ispi.net> schrieb im Newsbeitrag
news:1043251280.32189.64.camel@lena.ispi.prv...
> 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>
>