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

how to create a cache_id tip

 
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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
nlenz
Smarty n00b


Joined: 15 Aug 2003
Posts: 1

PostPosted: Fri Aug 15, 2003 4:57 pm    Post subject: how to create a cache_id tip Reply with quote

Something I figured out... if you need a cache_id that you don't want to worry about in the future:

$cache_id = md5($_SERVER['REQUEST_URI']);

or

$cache_id = md5('mything'.$_SERVER['QUERY_STRING']);

This way when you add something to your page in the future, say a printer friendly version by appending &printer=1 to the query string then you don't have to worry about keeping track of every little id that changes your page.

Of course this doesn't work in every situation.

One question though,...why doesn't smarty automatically take the QUERY_STRING into account when displaying a cached template (when not given a cache_id).

So if this code was executed with the following url's,...shouldn't they automatically return different caches?

$s->caching = true;
$s->display('coolpage.tpl');

http://somesite/coolpage.php?cool_thing=2
http://somesite/coolpage.php?cool_thing=3

Just some thoughts....
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Aug 15, 2003 7:10 pm    Post subject: Re: how to create a cache_id tip Reply with quote

nlenz wrote:

$cache_id = md5('mything'.$_SERVER['QUERY_STRING']);


That works so long as you want the entire QUERY_STRING to affect the page caching. FYI, you are still vulnerable to flood attacks filling up your hard disk with bogus cache files. Maybe some more strict checking should be implemented.

nlenz wrote:

One question though,...why doesn't smarty automatically take the QUERY_STRING into account when displaying a cached template (when not given a cache_id).


That behavior would be application independent, not something smarty should assume.
Back to top
View user's profile Send private message Visit poster's website
datamile
Smarty Rookie


Joined: 17 May 2003
Posts: 13

PostPosted: Tue Aug 19, 2003 9:21 pm    Post subject: Reply with quote

Never thought of that...

Normally build the cache id from the required parameters of the page , and then pass it to a translating routine which generates an ID in a mysql data if the cache id is over a certain lenght
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 -> Tips and Tricks All times are GMT
Page 1 of 1

 
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