Re: Please help on caching
| From: | Monte Ohrt | Date: | Fri, 28 Dec 2001 15:16:47 +0000 |
| Subject: | Re: Please help on caching | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-2405@lists.php.net to get a copy of this message | ||
"Brian E. Lozier" wrote:
>
> Have you gotten a method like this to work with a login system? The problem I've just run
> into is that if
> the first person to visit is logged in, the cached pages shows everyone following as logged in.
> *sigh* I
> wish there was a way to only cache certain templates that are retrieved via ->fetch(). Or
> that my cache
> would actually store two files... the 'main.tpl' (outer shell) and then the inner
> content itself. Then I
> could cache the content (inner) and not the outer, which doesn't depend on db calls
> anyway.
If you don't want a particular template cached, then you can turn off
caching before displaying it.
$smarty->caching = false;
$smarty->display('login.tpl');
>
> I guess the way this system is set up is that in order to use caching, you have to separate
> your design into
> multiple files and then use include statements... in which point it doesn't seem to be an
> advantage anyway.
> Pity I didn't realize this sooner, because 3/4 of my app is done and I'm just now
> realizing that the entire
> caching system simply doesn't work. Top that off with the fact that some of my pages are
> taking up to half a
> second to generate, and it makes the whole thing a lot slower than fasttemplate or phplib
> templates ever
> were.
No, you shouldn't have to do this. You just need to use the caching
appropriately for your application. Are you using Zend Cache or APC with
your application? Even without using Smarty's built-in caching, it
should still be quite fast, and most likely faster than other templating
solutions because there is no template parsing needed, it just executes
PHP scripts. The only noticable overhead would be the compilation of the
PHP scripts themselves, which is where APC or Zend Cache will make a
_huge_ difference in performance, and Smarty can take advantage of that
because all the templates _are_ PHP scripts. If your page loading times
are slow because of database calls, then the problem does not lie in
your templating solution.
>
> There needs to be some way to tell smarty to get the cached content for certain templates
> within a page but
> not others.
Caching happens at a "page" level. If you want certain components of
your page dynamic, use the {insert} function to create that content.
That is exactly what it is intended for.
> That way I can specify which parts of the pages I get from a cache and which I don't. For
> instance, I could cache the user comments on each article for an hour, but people should still
> be able to add
> articles, so I can't cache the add comment FORM itself (because there are hidden elements
> that tell the
> script which article the person is commenting on). I can cache the main news page that lists
> all the news
> from the database, but not the outer design because it has feedback letting the user know
> whether they're
> logged in or not (and displays more options when you're logged in than when you're
> not). Being able to cache
> certain templates only would be a big help because I could eliminate database calls altogether
> from the vast
> majority of pages, while still having the logged in feedback and other 'dynamic'
> content that simply must be
> dynamic.
You can obtain all of this by making non-cached components of your page
with the {insert} tag. that is exactly how we handle feedback, polls,
banners, or any other content that needs to remain dynamic on the page.
>
> Brian
> ------------------------------------
> "How should I know if it works? That's what beta testers are for. I only coded
> it." - Linus Torvalds
>
> ----- Original Message -----
> From: Peter Bowyer <reywob@f2s.com>
> To: smarty@lists.ispi.net
> Date: 12/27/01 3:34:09 AM
>
> >
> >At 04:06 PM 12/26/01 -0800, you wrote:
> >>I have queried this list quite a few times but nothing is helping. I
> >>upgraded to the latest version. I have
> >>tried all suggestions. Is this a bug in Smarty? Does anyone else have
> >>this "dynamic" content caching
> >>correctly using the cache_id? Because Smarty is just ignoring my cache_id
> >>I pass, no matter what it is.
> >>Please, I really need to get this working, it's important.
> >
> >I have it working with Smarty 1.4.5 - see it in action at
> ><http://casualties.commemoratewtc.com> where each
> >page is cached for 3 days.
> >
> >>Here is my 'main.tpl' which is the main layout of the site (note I
> >>replaced > and < with ] and [ because my
> >>email program strips the HTML for some reason):
> >>
> >>main.tpl:
> >>[html]
> >>[head][title]{$PageTitle}[/title][/head]
> >>[body]
> >>{$Content}
> >>[/body]
> >>[/html]
> >
> >Great - another coder who hates header/footer files and prefers the design
> >to be in one file! That now makes two of us for whom the "normal" smarty
> >method doesn't suit :-)
> >
> >>I have tried passing both $REQUEST_URI (which *is* passing correctly, I
> >>verified!) and $catID (since it's
> >>unique for each of the cache results I'm looking for) to main.tpl like:
> >>$tpl->display('main.tpl', $REQUEST_URI); // and:
> >>$tpl->display('main.tpl', $catID);
> >>
> >>I've also tried passing it to the $tpl->fetch() where I get the actual
> >>files.tpl template like:
> >>$tpl->assign("Content", $tpl->fetch('files.tpl',
> >>$REQUEST_URI));
> >
> >This is the right one. After this, just call $tpl->display('main.tpl'); and
> >it should work. You could always try $tpl->display('main.tpl',
> >$REQUEST_URI); as well.
> >
> >Did you clear the cache and the compiled templates before you tried this?
> >
> >Sorry I can't be more help.
> >Peter.
> >
> >--
> >Maple Design - http://www.mapledesign.co.uk
> >
> >
> >---
> >You are currently subscribed to smarty as: brian@massassi.net
> >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/
--
Monte Ohrt <monte@ispi.net>
http://www.ispi.net/