Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

{cache} {/cache}
Goto page Previous  1, 2, 3, 4
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu May 04, 2006 12:51 am    Post subject: Reply with quote

OpenMacNews wrote:

<ste: clipcache id=test group=foo ttl=5 ldelim=<ste: rdelim=:ste> :ste>
BLAH BLAH BLAH
<ste: /clipcache id=test group=foo ttl=5 ldelim=<ste: rdelim=:ste> :ste>

causes an error:

Fatal error: Smarty error: [in test.tpl line 59]: syntax error: unrecognized tag 'clipcache' (Smarty_Compiler.class.php, line 580) in /path/to/Smarty.class.php on line 1095

which, i'm guessingm may be a problem with my non-standard delims of '<ste:' & ':ste>', though not sure. wan't entirely clear to me if the prior page's delim def'n support was 'in there' already ...


There is a modicum of support for private delims but you seem to be mis-using them. Recall the earlier example:

Code:
{clipcache id=foo group=bar ttl=300 ldelim=(: rdelim=:)}

{foobar} <-- not interpreted as a smarty tag in this block
(: include file=foobar.txt :) <-- interpreted as a smarty tag in this block

{/clipcache  id=foo group=bar ttl=300 ldelim=(: rdelim=:)}


the ldelim and rdelim attributes are used to change from the current delimiters [eg: {, }] to new delimiters within the clipcache block [eg: (:, Smile]. In your case, you don't seem to actually change the delims and that confuses the parsing. It seems you can simply use:

Code:

   <ste: clipcache id=test group=foo ttl=5 :ste>
      BLAH BLAH BLAH
   <ste: /clipcache id=test group=foo ttl=5 :ste>


Within the clipcache block, you would still use your custom delims. Of course, I wouldn't push that feature too hard Smile

HTH
Back to top
View user's profile Send private message
OpenMacNews
Smarty Rookie


Joined: 03 Aug 2004
Posts: 34
Location: Floating on Io's Methane Seas ...

PostPosted: Thu May 04, 2006 1:09 am    Post subject: Reply with quote

well, for a moment there, i was encouraged Wink

changing to recommended code:

Code:
<ste: clipcache id=test group=foo ttl=5 :ste>
      BLAH BLAH BLAH
<ste: /clipcache id=test group=foo ttl=5 :ste>


i'm unfortunately still seeing the error:

Quote:
Fatal error: Smarty error: [in test.tpl line 59]: syntax error: unrecognized tag 'clipcache' (Smarty_Compiler.class.php, line 580) in /path/to/Smarty.class.php on line 1095


so, it seems that it may be something else ...

this functionality will be hugely useful ... i'm happy to play 'guinea pig' as much as needed, as your intereste dictates!

Smile

cheers
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu May 04, 2006 3:51 am    Post subject: Reply with quote

Heh. My mistake. As I said, there is a modicum of support for this right now Smile The regex is very simple atm and does not allow spaces between the clipcache tagname and the delimiters, so this should work:

Code:
<ste:clipcache id=test group=foo ttl=5 :ste>
      BLAH BLAH BLAH
<ste:/clipcache id=test group=foo ttl=5 :ste>


However, I updated the regex (without bumping the version) in the posted code so you can test that if you like. Personally, I think it looks kinda funny but I guess it should be supported. Hmmm, it seems the parsing could use some attention for the next release. The need to mirror the attributes in the close tag bothers me. Mad

Thanks for testing and reporting issues, OpenMacNews!
Back to top
View user's profile Send private message
OpenMacNews
Smarty Rookie


Joined: 03 Aug 2004
Posts: 34
Location: Floating on Io's Methane Seas ...

PostPosted: Thu May 04, 2006 5:26 am    Post subject: Reply with quote

hi boots,

Quote:
However, I updated the regex (without bumping the version) in the posted code so you can test that if you like.


updated to bumped code.

with or without the spaces, per:

Code:
<ste:clipcache id=test group=foo ttl=5 :ste>
      BLAH BLAH BLAH
<ste:/clipcache id=test group=foo ttl=5 :ste>



i now get:

Code:
Fatal error: Using $this when not in object context in /path to/plugins/prefilter.clipcache.php on line 74


checking @ 74:

Code:
$write_path = rtrim( $this->compile_dir, "/\\" ) . DIRECTORY_SEPARATOR;


which looks like you added the rtrim from an later post ...

Quote:
Personally, I think it looks kinda funny


same here. BUT, with my 'custom' delims, i *know* with certainty that i can search/replace open/close tags without error ... worth the tradeoff for me.Smile

Quote:
Thanks for testing and reporting issues,


heh, it's a work of art in progress! Smile

thanks,

richard
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu May 04, 2006 7:44 am    Post subject: Reply with quote

OpenMacNews wrote:
Code:
$write_path = rtrim( $this->compile_dir, "/\\" ) . DIRECTORY_SEPARATOR;


which looks like you added the rtrim from an later post ...


Embarassed yipes, my bad. $this should be $compiler. I silently updated the code again without bumping versions.

Thanks!
Back to top
View user's profile Send private message
OpenMacNews
Smarty Rookie


Joined: 03 Aug 2004
Posts: 34
Location: Floating on Io's Methane Seas ...

PostPosted: Thu May 04, 2006 7:54 am    Post subject: Reply with quote

hi,

boots wrote:
$this should be $compiler. I silently updated the code again without bumping versions.


and with that, no more errors, and page displays properly ...
in the morning i'll start thinking about how to test/benchmark.

cheers & thx again!

richard
Back to top
View user's profile Send private message
OpenMacNews
Smarty Rookie


Joined: 03 Aug 2004
Posts: 34
Location: Floating on Io's Methane Seas ...

PostPosted: Wed May 10, 2006 10:19 pm    Post subject: Reply with quote

hi boots,

i've gotten far enuf along in ZF+Smarty to actually start looking at {clipcache} usage in detail when in ZF.

in my Zend_View class extension i've:


===============================================
...
protected function _run($template)
{
$this->_smarty->assign('smarty', $this);
$this->_smarty->register_clipcache();
$this->_smarty->display($template);
}
...
===============================================

which i'm fairly certain (?) is the right place to call register_clipcache();

BUT, if in:

test.tpl:
===============================================
<ste: clipcache id=test group=foo ttl=0 :ste>
BLAH
<ste: /clipcache id=test group=foo ttl=0 :ste>
===============================================

nav to the calling page viz Zend FrontController results in:

Warning: Smarty error: unable to read resource: "/webapps/resources/templates/test.tpl#test" in /webapps/tools/smarty/libs/Smarty.class.php on line 1095

checking in Smarty.class.php ...


/**
* trigger Smarty error
*
* @param string $error_msg
* @param integer $error_type
*/
function trigger_error($error_msg, $error_type = E_USER_WARNING)
{
1095 trigger_error("Smarty error: $error_msg", $error_type);
}


suggestions where to look for trouble?

cheers,

richard
Back to top
View user's profile Send private message
Amadiere
Smarty Rookie


Joined: 20 Feb 2006
Posts: 5

PostPosted: Wed May 17, 2006 10:12 am    Post subject: Reply with quote

Excellent function!
I have just had a little bit of a problem with an install on my Windows setup.

In prefilter.clipcache.php on line 76 (ish):
Code:
$file_name = $compiler->_current_file.'#' . $id;


When I examined why I was having a load of "failing to create a directory", it didn't seem to be permissions problem. But was due to the fact that I believe the variable $compiler->_current_file has a different output depending on the operating system.

The way it appears to be used here is as if it contains the name of the file only. However, on Windows (or I should say "my setup") it returned the entire path. Which meant when it was concatinating it to create the name of the directory you had something along the lines of:
Code:
C:/whataver/compile/clipcache/C:/whatever/content/template.tpl


My fix isn't too nice, rather crude actually - but it suits my scenario. I have an array of global configs that I provided the 'smarty_prefilter_clipcache' function access to, before altering the above mentioned line to:
Code:
$file_name = str_replace($config[STATUS]['content_dir'].'\\',"",$compiler->_current_file).'#' . $id;


I'm quite happy (currently) with my fix. If anyone spots any flaws in my knowledge I wouldn't mind some constructive critism. Twisted Evil

Again, an excellent function boots! Great work!
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed May 17, 2006 2:56 pm    Post subject: Reply with quote

Hi Amadiere.

Thanks for the comments! I traced this issue with OpenMacNews on IRC and discovered that the problem seems to be a little bit more involved (you are close, though). I actually have a fix but I have forgotten to update the code (it is sitting on my home machine so I can't do it right now). I can sum it up like this: you can NOT use absolute paths to call templates. With my fix, you can convert an absolute path to a relative path but only if the absolute path is part of the template_dir path -- otherwise it fails. So basically, in its current state clipcache does not support:

- resources
- multiple template dirs
- absolute paths outside of the template_dir

and absolute paths inside the template_dir will only be supported if you manually convert them to relative paths with a helper function that I (will) provide on the Smarty_ClipCache class.

I'll post the updated fix tonight.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu May 18, 2006 7:26 am    Post subject: Reply with quote

I've decided to post the code at the wiki. I'm no longer updating the code in this thread but we can still discuss the addon here Smile

Get the latest 0.1.7 version: http://smarty.incutio.com/?page=ClipCache

Note that the new Smarty_ClipCache::absolute2relative() method has not yet been tested and will likely be improved in a future version.
Back to top
View user's profile Send private message
HeadY
Smarty n00b


Joined: 26 Jun 2007
Posts: 3

PostPosted: Wed Jul 18, 2007 3:06 pm    Post subject: Reply with quote

Hi,

nice plugin!
But i have a problem with dynamic IDs. Ill do:
Code:
{assign var="cacheID" value="user_"|cat:$data.user_id}
{clipcache id=$cacheID group=profile ttl=300}

in my Template and get:
Code:
Warning: Smarty error: unable to read resource: "box_right_news.tpl#->_tpl_vars['cacheID']" in /.../Smarty/Smarty.class.php on line 1095


Whatīs the ID and GROUP for when i cant assign them with some dynamic content? Sad

But the Performance is great!
11 DB Queries -> 0,084 sec
04 DB Queries -> 0,029 sec
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Jul 19, 2007 8:05 am    Post subject: Reply with quote

Hi.

Thanks for the nice comments! Admittedly, ClipCache is somewhat under achieving in regards to dynamic assignments. From memory alone, it occurs to me that this is probably caused by the fact that the logic for the ClipCache replacements occur in a prefilter (ie: at runtime) which do not fully consider evaluating the assigned parameter values as full-fledged Smarty expressions when generating the resulting code.

That's probably because I never needed that feature for myself Wink ... but of course, patches are welcome Smile

Best!
Back to top
View user's profile Send private message
HeadY
Smarty n00b


Joined: 26 Jun 2007
Posts: 3

PostPosted: Mon Aug 13, 2007 3:48 pm    Post subject: Reply with quote

Well,

i got the right cache ID with a "fix" in the prefilter.clipcache.php:
Code:
$this = &$compiler;
eval ("\$id = $id;");
$file_name = $compiler->_current_file.'#' . $id;


But then the script loads the first cached Data Sad
I donīt understand why and how the Smarty/Clipcache System works.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Aug 13, 2007 5:50 pm    Post subject: Reply with quote

Hmmm. I strikes me that eval'ing the id is not the right solution here. Maybe better to use something like $compiler->_parse_var( $id ) ? Haven't thought about it too hard, so I don't know for sure.

Anyways, sorry if the code isn't clear enough. {clipcache} attempts to do something that Smarty wasn't designed for; as a result, it pushes the plugin architecture a bit more than is usual for most addons/plugins. If you have specific questions on how the system works, I'll try to answer them.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Goto page Previous  1, 2, 3, 4
Page 4 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP