Re: Please help on caching
| From: | Monte Ohrt | Date: | Fri, 28 Dec 2001 23:17:12 +0000 |
| Subject: | Re: Please help on caching | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-2430@lists.php.net to get a copy of this message | ||
Maybe there is a better way to approach your problem.
If I understand correctly, you should be able to do something like this:
// $page is our identifier for our content
$smarty->assign("page",$page);
// possibly use $page or $REQUEST_URI for the cache_id, depeding on if
you need separate caches per $page or not
$smarty->display('main.tpl',$REQUEST_URI);
main.tpl
---------
<html>
<body>
{if $page eq "article"}
{include file="article.tpl"}
{elseif $page eq "category"}
{include file="category.tpl"}
{else}
{include file="default.tpl"}
{/if}
</body>
</html>
This way, the page fetching happens all in one go, under one cache file
(for each cache_id).
Does this help at all?
Monte
"Brian E. Lozier" wrote:
>
> >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');
>
> See, this is why I don't think you guys are understanding my problem. *ALL* my
> $tpl->display() calls look
> like:
>
> $tpl->display('main.tpl');
>
> At the end of EVERY page in my application. Because 'main.tpl' contains my entire
> design.
>
> [html][body]
> {Content}
> [/body][/html]
>
> Then I populate {Content} with a $tpl->fetch() command, such as:
>
> $tpl->assign('Content', $tpl->fetch('userregister.tpl'));
>
> The problem is that it's always trying to cache main.tpl exactly the same no matter what.
> If I pass a
> $REQUEST_URI, it still does the same thing. If I pass a $REQUEST_URI to the ->fetch(), it
> caches my content
> correctly, but there's no way to tell ->display('main.tpl') to use *that*
> cached content. See, since I never
> call $tpl->display('userregister.tpl'), there's no way to 'turn off
> caching' before I do that, because that
> step never takes place.
>
> And I tried turning off (and turning on) caching just before the fetch, but it still
> doesn't work. It
> returns nothing at that point.
>
> >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.
>
> I'm not using any of those. Smarty is taking half a second 0.576877 or whatever, and the
> rest are taking
> 0.08587575 or something. When I turn on caching, smarty is returning the page in comparable
> amounts of time.
>
> >> 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.
>
> This is the very root of the problem. Since Smarty thinks *all* my pages are
> 'main.tpl' it can't correctly
> cache the parts I want. I can't use insert, because I populate the {$Content} portion of
> my main.tpl
> depending on what page they're accessing. And the {$Content} is what I want cached, not
> the main.tpl.
> main.tpl doesn't require any database calls, just some basic logic such as {if $Logged}
> {/if}, etc. But
> since that gets cached, I have to have a way not to cache main.tpl.
>
> >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.
>
> That doesn't make much sense, because then you're placing logic inside the design
> templates. You're forcing
> me, ahead of time, to write a function (of which I have *2* in my entire project, the rest of
> all my
> functionality is in objects and methods) that corrosponds with whatever content isn't
> cached. So this means
> I have to write a PHP function to do some very simple HTML display/presentation stuff like
> outputting a
> simple form. Also, since everything is in main.tpl, I can't just pick some specific point
> and add an
> {insert} tag.
>
> Take for instance my 'right hand sidebar' - this is where I would put the poll, or
> the featured articles
> list, or whatever I want. But my application can replace the 'standard' sidebar with
> virtually any content
> it wants (for instance, in the admin section, the admin options are there... in the files
> section,
> thumbnailed screenshots appear there). There is no way to make one canned {insert} function
> that can handle
> all of these options. And if the content isn't dynamic for that page, IE: if it uses the
> stock one, it
> should be able to cache it.
>
> I think the reason this is so hard to explain is because nobody else (except that one guy) has
> ever use the
> templates like this. You guys are using two {include} statements, one at the top and one at
> the bottom, to
> hold your design. From the beginning, this was what I wanted to get away from, because it
> forces me to make
> an artificial split (or 5 or 6 depending on the complexity of the design) in my design. It
> confuses the
> designers to have to view their page in multiple files split up in the middle of xx number of
> nested tables.
>
> I've tried what seems like a dozen different ways of explaining this, but most people
> aren't understanding
> for some reason. I don't know what else to say... Thanks again for all the help, though.
>
> >>
> >> ----- 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/
> >
> >---
> >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/
--
Monte Ohrt <monte@ispi.net>
http://www.ispi.net/