ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Caching embedded templates

May 04, 2010 4:36am

Subscribe [9]
  • #1 / May 04, 2010 4:36am

    Yuri

    315 posts

    I have a main templates (not cached) that includes a call to embedded templates (which is cached with 30 minutes interval)
    However it appears that the embedded template is not cached - I have ‘Page loaded in {elapsed_time} seconds’ string in there, and it outputs different result each time.
    I’m running the latest biuld of EE 1.6.9
    So my questions are:
    1. Are the embbedded templates supposed to be cached at all?
    2. If yes, are they cached relevantly to the templates they have beed called from - or just one cache file per template?
    3. If no, what would be the suggested practice to cache templates embbeded within non-cacheable template?
    4. Is there anything I’m doing wrong perhaps? 😊

  • #2 / May 04, 2010 8:38am

    Sue Crocker

    26054 posts

    Try running your cached template by itself. Does it work like you expect?

  • #3 / May 04, 2010 8:43am

    Yuri

    315 posts

    It’s a hidden templates (name prefixed with dot .)
    However if I remove the dot and call the template in browser - it is cached

  • #4 / May 04, 2010 4:01pm

    Ingmar

    29245 posts

    Caching is done on a per-URL level, not a template level: if you have the same template that is used to power each of your articles you will have a copy for each URL, same with embedded templates, if you embed the sidebar template into each page and you cache the sidebar template, you will have a copy for each URL.

    To further quote Nevin:

    Unless you actually are seeing a specific need, for a specific template, to be cached, I would highly recommend to not cache unless you have to. That goes for query caching, too.

  • #5 / May 04, 2010 4:26pm

    Yuri

    315 posts

    I do need to cache the embedded templates - that was actually the reason to split the template into parts.

    So, if the ‘main’ template is not cached - will embedded template be cached or am I doing something wrong?

    What would be the suggested practice then? Will placing a call to embedded template inside cacheable tag make them cached?

  • #6 / May 04, 2010 7:43pm

    Brandon Jones

    5500 posts

    What would be the suggested practice then?

    If you must cache, I suppose you could lump everything back into a single template.

    Will placing a call to embedded template inside cacheable tag make them cached?

    You may want to experiment with is, but as Ingmar said caching happens on a URL basis because information from the URL is used when parsing templates.

  • #7 / May 05, 2010 3:38am

    Yuri

    315 posts

    I need to cache everything except one tag. Is there a way to force one tag to be not cached while the rest of template is cached?

  • #8 / May 05, 2010 12:03pm

    Sue Crocker

    26054 posts

    No, unfortunately there isn’t.

  • #9 / May 05, 2010 12:27pm

    Brendon Carr

    135 posts

    Yes, there is. But you’ll need to pay some money. Solspace’s Template Morsels ($42.95) does what Yuriy is after.

  • #10 / May 05, 2010 2:01pm

    Natebot

    40 posts

    I’m not understanding why Nevin recommends avoiding template caching except in cases of “a specific need”.  Perhaps I am taking it out of context. Unless we define “a specific need” as handling high traffic to process-heavy pages, I am finding that caching is essential for EE to be performant under heavy traffic.

    My practice is to minimize the number of sub-templates (each generates a query, though it appears my DB’s cache is responding, rather than disk seeking). Uncached portions of the page - such as logged in user data - are placed in sub templates but otherwise portions of the page, such as the blog post, header, etc are cached.  Does this strike anyone as inappropriate or wasteful?

  • #11 / May 05, 2010 3:33pm

    Ingmar

    29245 posts

    Natebot, please start a new thread if you want to discuss this in detail. Yuriy, does that answer your questions? Any remaining tech support issues there?

  • #12 / May 05, 2010 10:18pm

    Nevin Lyne

    370 posts

    Natebot,

    If you want to open a new thread with your question, and PM me the URL I would be happy to answer, though I may also include references to other past forum threads I have addressed your question in before too.

    I will quickly say that I don’t make recommendations lightly, and I am taking them from our experiences of watching, analyzing, and consulting with thousands of hosting client over the years.  A lot of my recommendations are generally geared at sites with large amounts of content and large traffic levels, ie: 10’s of thousands to millions of weblog(channel) entries, and 10’s of millions of EE powered page views per month.  But in many cases the same examples can apply to almost any web site under pretty common situations.  Over the years many of the actual performance tweets, changes and settings added into EE have come directly from working with the Dev team on identifying and targeting things we are seeing on sites hosted with EngineHosting.  So if you have never hosted a web site with EngineHosting, I can guarantee you have gotten benefits from the clients that do. All I can say is in the end my recommendations are 100% from direct experience with big, busy EE sites.

    There is a lot more to it than simply my quote above, you really need to understand the overall implications of over caching and how EE’s cache actually functions.

    I look forward to your separate thread, if you still have questions.

  • #13 / May 06, 2010 4:57am

    Yuri

    315 posts

    ok, here’s the solution I came to

    I found out that I can place the code I need to be NOT cached into subtemplate (which is not cached).
    I include it with embed into ‘main’ template, which I can not set to cacheable.
    It works just the way I need! - everything is cached except what is in embedded non-cacheable template.

    Template morsels also improve perfomance - they work faster than regular embeds. It’s a pity they can’t be used everywhere.

    Ingmar, you can close the thread.

    Thank you for your help, everyhone.

  • #14 / May 06, 2010 11:17am

    Sue Crocker

    26054 posts

    Thanks for the assist, everyone. Don’t hesitate to post again as needed.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases