Re: Question about selective caching.

From: Date: Fri, 11 Jan 2002 23:35:15 +0000
Subject: Re: Question about selective caching.
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-2523@lists.php.net to get a copy of this message
Use your $REQUEST_URI as the cache_id: global $REQUEST_URI; // only if needed $smarty->display($tpl_name,$REQUEST_URI); This will create a separate cache file for each unique URL when you call $tpl_name. Luc Saint-Elie wrote: > > Monte, > > Thanks a lot, it works and I start to understand. > > If I understand well the path for caching is : > > 1- set the caching to true > 2- do a fetch() for the template (*.tpl) file, this somehow simulates the > browser and produce the output > 3- assign the content to Smarty as a variable > 4- place the corresponding variable in the main template (and don't use > anymore include file= ) > 5 - set caching to false > > And on the top of that do a check to see if the file has been previously > cached. > If this is right, maybe this may be a good idea to add this to the caching > part of the doc > > Now another question : > > This work for a *.tpl file which content is not linked to a set of url > variables. > > I'd like to cache a *.tpl file (in fact a set of different version of this > *.tpl) that is used to display a members list based on the member type > (man, woman, couples...) or location > The called url is of the form : > ’ý¬@\! > 1abûmË�å]http://www.mydomain.com/members.php?a=list&sex=1&location=0 > > In members.php I've something like (simplified form) : > > case 'list' : $smarty->assign("data", > $myuserclass->user_getMembers($id,$sex,$location)); > $smarty->assign('centre',$menu['centre'] ); > > [...] > > if(!isset($tpl_name)){$tpl_name ='index.tpl';} > $smarty->display($tpl_name); > > In this case index.tpl is the main template and the content of 'data' is > looped in a sub-template which name is contained in $menu['centre'] > > I'm not very clear about how will this work with a cache, in fact in an > ideal world I'd like a cached file for each combination of url's passed to > the *.php file > > If I do something like : > > $tpl = $smarty->fetch($menu['centre']); how do I indicate the url variables > ? (in this case "sex=1&location=0") > > Thanks in advance > > Luc > > At 10:30 11/01/02 -0600, Monte Ohrt wrote: > >One way to do it: > > > >$smarty->caching = true; > >$tpl1 = $smarty->fetch("internal1.tpl"); > >$tpl2 = $smarty->fetch("internal2.tpl"); > >$tpl3 = $smarty->fetch("internal3.tpl"); > > > >$smarty->assign("tpl1_contents",$tpl1); > >$smarty->assign("tpl2_contents",$tpl2); > >$smarty->assign("tpl3_contents",$tpl3); > > > >$smarty->caching = false; > >$smarty->display('index.tpl'); > > > >index.tpl > >--------- > > > ><table> > > <tr> > > <td>{$tpl1_contents}</td> > > <td>{$tpl2_contents}</td> > > <td>{$tpl3_contents}</td> > > </tr> > ></table> > > > > > > > > > >Another approach: > > > >You could write a custom insert function to fetch your internal > >templates: > > > ><table> > > <tr> > > <td>{insert name=fetch_tpl tpl="internal1.tpl"}</td> > > <td>{insert name=fetch_tpl tpl="internal2.tpl"}</td> > > <td>{insert name=fetch_tpl tpl="internal3.tpl"}</td> > > </tr> > ></table> > > > > > >Luc Saint-Elie wrote: > > > > > > Hello all, > > > > > > Its still me with my infamous caching problems..... > > > > > > My web site is some kind of portal-like site with a main template (*.tpl) > > > named index.tpl that is some kind of table and that includes a lot of other > > > templates files (*.tpl) in each of the cells. > > > > > > I can't cache the main one (because it simply doesn't work for me) but > > > that's not a real problem because the *.php produced file doesn't really > > > change a lot so I'm not sure that speed increase will be huge. > > > > > > On the other side I have some of the internal included files that I would > > > like to cache because theses internal *.tpl files are fed by database data > > > and these data doesn't change so often (for example one of them display a > > > list of news title, but I had news twice a week) > > > > > > So my question: I'm looking for a example (a working one preferably) of a > > > cache for a given template that is included in a main one, because I > > > absolutely don't understand how it is done. > > > > > > Thanks in advance > > > > > > Luc > > > > > > --- > > > You are currently subscribed to smarty as: monte@ispi.net > > > To unsubscribe send a blank email to $subst('Email.Unsub') > > > Visit Smarty's homepage at > > > http://www.phpinsider.com/php/code/Smarty/ > > > >-- > >Monte Ohrt <monte@ispi.net> > >http://www.ispi.net/ > > > >--- > >You are currently subscribed to smarty as: luc@saint-elie.com > >To unsubscribe send a blank email to $subst('Email.Unsub') > >Visit Smarty's homepage at > >http://www.phpinsider.com/php/code/Smarty/ > > --- > You are currently subscribed to smarty as: monte@ispi.net > To unsubscribe send a blank email to $subst('Email.Unsub') > Visit Smarty's homepage at http://www.phpinsider.com/php/code/Smarty/·¿Ï½ > v'ŠF.£ßLo -- Monte Ohrt <monte@ispi.net> http://www.ispi.net/

« previous php.smarty.general (#2523) next »