Re: [SMARTY-DEV] Here it is: Patch for {nocache} support

From: Date: Mon, 14 Apr 2003 18:08:03 +0000
Subject: Re: [SMARTY-DEV] Here it is: Patch for {nocache} support
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-1151@lists.php.net to get a copy of this message
Cache functionality is the next major project for Smarty, this has been waiting for post-2.5.0 release. There have been lots of discussions on this in the recent past, and I think the most prominent method that stood out was the ability to register a function as cached or non-cached. Then if you wanted the {cache}{/nocache} functionality, you could register a block function called "nocache" that is marked as a non-cached function. Monte On Mon, 2003-04-14 at 11:18, André Rabold wrote: > Attention folks, > the following patch is pre-pre-pre-beta ;-) But it should work well with > Smarty 2.5.0. > > Here's what can be done with it: > > Imagine you have a cached template but want some parts to never get cached. > In this case you needed to use an insert tag {insert type="foo"}. I don't > like this approach even if I know alot other people do ;-) It splits my > templates too much because I use alot of user-specific buttons and links. > After applying this patch the following is possible: > > {* This is a cached template *} > This is cached: {$foo} > {nocache}This is not cached: {$foo}{/nocache} > This is cached again: {$bar} > > It work's pretty well for me even if it's not that fast anymore because I am > using an eval() call :-( Perhaps this can be fixed in a later version... But > hey, it's faster than not using any caching at all. > > For outputting the value of a single variable you can do > {nocache}{$foo}{/nocache} or even {$foo|nocache} which prevents $foo from > beeing cached too. You can even prevent a plugin function from beeing > cached: {foo|nocache bar="blah"} > > Attention: You cannot use the nocache modifier with function parameters yet. > Things like {foo bar=$foo|nocache} won't work for now. I'll implement this > asap. > > What I want to do now is to change the register_function to use an > additional parameter "cached". This way you could do something like > $smarty->register_function("foo", foo, false). That's because {nocache} tags > and modifiers gives too much possibilities to our designers. A designer > shouldn't need to care if a specific function needs to be cached or not. > It's better to let the developer decide, isn't it? > > ATTENTION AGAIN: The following patch is not testet in a productive > environment. It works well for me but who knows if it works for you ;-) > > > What do you think? Any ideas? > > Bye, > André > > > > Index: Smarty.class.php > =================================================================== > RCS file: /repository/smarty/libs/Smarty.class.php,v > retrieving revision 1.375 > diff -r1.375 Smarty.class.php > 1107a1108 > > $_smarty_results = > $this->_eval_cached_template($_smarty_results); > 1176a1178 > > $_smarty_results = > $this->_eval_cached_template($_smarty_results); > 1890d1891 > < > 1893c1894,1907 > < > --- > > > > function _eval_cached_template($results) { > > $cacheSmarty = new Smarty(); > > $cacheSmarty->left_delimiter = "<!--{#SMARTYCACHE#"; > > $cacheSmarty->right_delimiter = "}-->"; > > $cacheSmarty->caching = 0; > > $cacheSmarty->_tpl_vars = $this->_tpl_vars; > > $cacheSmarty->_compile_template("evaluated template", $results, > $source); > > ob_start(); > > eval('?>' . $source); > > $results = ob_get_contents(); > > ob_end_clean(); > > return $results; > > } > > > > Index: Smarty_Compiler.class.php > =================================================================== > RCS file: /repository/smarty/libs/Smarty_Compiler.class.php,v > retrieving revision 1.204 > diff -r1.204 Smarty_Compiler.class.php > 388a389,391 > > if (($this->_within_nocache && $tag_command != "/nocache") || > ($this->caching && > in_array("nocache",explode("|",$tag_modifier)))) { > > return "<!--{#SMARTYCACHE#".$template_tag."}-->"; > > } > 488a492,501 > > case 'nocache': > > if ($this->caching > 0) > > $this->_within_nocache = true; > > return ""; > > > > case '/nocache': > > if ($this->caching > 0) > > $this->_within_nocache = false; > > return ""; > > > 1625a1639,1642 > > continue; > > } > > else if($_modifier_name == 'nocache') { > > // skip nocache modifier > > > > begin 666 nocache-patch.txt > M26YD97@Z(%-M87)T>2YC;&%S<RYP:' -"CT]/3T]/3T]/3T]/3T]/3T]/3T] > M/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T] > M/3T-"E)#4R!F:6QE.B O<F5P;W-I=&]R>2]S;6%R='DO;&EB<R]3;6%R='DN > > M8VQA<W,N<&AP+'8-"G)E=')I979I;F<@<F5V:7-I;VX@,2XS-S4-"F1I9F8@ > M+7(Q+C,W-2!3;6%R='DN8VQA<W,N<&AP#0HQ,3 W83$Q,#@-"CX@(" @(" @ > M(" @(" @(" @("1?<VUA<G1Y7W)E<W5L=',@/2 > D=&AI<RT^7V5V86Q?8V%C > M:&5D7W1E;7!L871E*"1?<VUA<G1Y7W)E<W5L=',I.PT*,3$W-F$Q,3<X#0H^ > M(" @(" @(" @(" @("1?<VUA<G1Y7W)E<W5L=',@/2 > D=&AI<RT^7V5V86Q? > M8V%C:&5D7W1E;7!L871E*"1?<VUA<G1Y7W)E<W5L=',I.PT*,3@Y,&0Q.#DQ > M#0H\( T*,3@Y,V,Q.#DT+#$Y,#<-"CP@#0HM+2T-"CX@(" @( T*/B @(" @ > M9G5N8W1I;VX@7V5V86Q?8V%C:&5D7W1E;7!L871E*"1R97-U;'1S*2![#0H^ > M(" @(" @("1C86-H95-M87)T>2 ](&YE=R!3;6%R='DH*3L-"CX@(" > @(" @ > M)&-A8VAE4VUA<G1Y+3YL969T7V1E;&EM:71E<B ]("(\(2TM>R-334%25%E# > M04-(12,B.PT*/B @(" @(" D8V%C:&53;6%R='DM/G)I9VAT7V1E;&EM:71E > M<B ](")]+2T^(CL-"CX@(" @(" @)&-A8VAE4VUA<G1Y+3YC86-H:6YG(#T@ > M,#L-"CX@(" @(" @)&-A8VAE4VUA<G1Y+3Y?='!L7W9A<G,@/2 > D=&AI<RT^ > M7W1P;%]V87)S.PT*/B @(" @(" D8V%C:&53;6%R='DM/E]C;VUP:6QE7W1E > M;7!L871E*")E=F%L=6%T960@=&5M<&QA=&4B+" > D<F5S=6QT<RP@)'-O=7)C > M92D[#0H^(" @(" @(&]B7W-T87)T*"D[#0H^(" @(" @(&5V86PH)S\^)R N > M("1S;W5R8V4I.PT*/B @(" @(" D<F5S=6QT<R ](&]B7V=E=%]C;VYT96YT > M<R@I.PT*/B @(" @("!O8E]E;F1?8VQE86XH*3L-"CX@(" @(" @<F5T=7)N > M("1R97-U;'1S.PT*/B @(" @?0T*#0H-"@T*26YD97@Z(%-M87)T>5]#;VUP > M:6QE<BYC;&%S<RYP:' -"CT]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T] > M/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T-"E)#4R!F > M:6QE.B O<F5P;W-I=&]R>2]S;6%R='DO;&EB<R]3;6%R='E?0V]M<&EL97(N > > M8VQA<W,N<&AP+'8-"G)E=')I979I;F<@<F5V:7-I;VX@,2XR,#0-"F1I9F8@ > M+7(Q+C(P-"!3;6%R='E?0V]M<&EL97(N8VQA<W,N<&AP#0HS.#AA,S@Y+#,Y > M,0T*/B @(" @(" @(&EF("@H)'1H:7,M/E]W:71H:6Y?;F]C86-H92 F)B D > M=&%G7V-O;6UA;F0@(3T@(B]N;V-A8VAE(BD@?'P@*"1T:&ES+3YC86-H:6YG > > M("8F(&EN7V%R<F%Y*")N;V-A8VAE(BQE>'!L;V1E*")\(BPD=&%G7VUO9&EF > M:65R*2DI*2![#0H^(" @(" @(" @("!R971U<FX@(CPA+2U[(U--05)464-! > M0TA%(R(N)'1E;7!L871E7W1A9RXB?2TM/B([#0H^(" @(" @(" @?0T*-#@X > M830Y,BPU,#$-"CX@(" @(" @(" @(" @8V%S92 G;F]C86-H92<Z#0H^(" @ > M(" @(" @(" @(" @("!I9B H)'1H:7,M/F-A8VAI;F<@/B P*0T*/B > @(" @ > M(" @(" @(" @(" @(" > D=&AI<RT^7W=I=&AI;E]N;V-A8VAE(#T@=')U93L- > M"CX@(" @(" @(" @(" @(" @(')E='5R;B > B(CL-"CX@(" @(" @(" @(" @ > M#0H^(" @(" @(" @(" @(&-A<V4@)R]N;V-A8VAE)SH-"CX@(" > @(" @(" @ > M(" @(" @(&EF("@D=&AI<RT^8V%C:&EN9R ^(# I#0H^(" @(" > @(" @(" @ > M(" @(" > @("1T:&ES+3Y?=VET:&EN7VYO8V%C:&4@/2!F86QS93L-"CX@(" @ > M(" @(" @(" @(" @(')E='5R;B B(CL-"CX@(" @(" > @(" @(" @(" @( T* > M,38R-6$Q-C,Y+#$V-#(-"CX@"0D)"6-O;G1I;G5E.PT*/B )"0E]#0H^( D) > M"65L<V4@:68H)%]M;V1I9FEE<E]N86UE(#T]("=N;V-A8VAE)RD@>PT*/B ) > ?"0D)+R\@<VMI<"!N;V-A8VAE(&UO9&EF:65R#0H-"@`` > ` > end -- Monte Ohrt <monte@ispi.net>

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