Jump to:

23555 Posts in 19382 Topics by 2892 members

General Questions

SilverStripe Forums » General Questions » Caching strategy for largely static site with small amount of dynamic content on some pages.

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 698 Views
  • vwd
    Avatar
    Community Member
    158 Posts

    Caching strategy for largely static site with small amount of dynamic content on some pages. Link to this post

    Hi,

    What caching strategy would you recommendation for a largely static site which has some dynamic content (eg. a photo feed from another server) on some of the pages?

    I would imagine that I would use Static Publisher for all static pages, and then partially cache the pages with the partial dynamic content. Am I correct?

    But what I'm particularly curious about is how to use partial caching when a page is largely static but contains only a small amount of dynamic content. Would I put a partial cache block around most of the rest of template with no key (ie so it re-caches after the default TTL) and then cache block with appropriate keys around the dynamic portions of the template? I don't see any examples where it is done like this. For example, usually the majority of a page is static (eg. head, navigation bar, footer) - it seems strange to have to insert partial cache blocks around all these parts of the template. So how would we go about caching the majority of the page, and then using the partial cache blocks with appropriate keys for the dynamic portions? I'd imagine this is a fairly common issue?

    <html>
    <head>
    <% include HeadDetails %>
    </head>
    <body>
    <div id="container">
    <% include Header %>
    <% include NavBar %>

    $Content
    $Form

    <%-- I want the PhotoFeedFromFlickr template portion to be re-cached only if a new photo is in the stream, but otherwise, the rest of the page should be cached always for the default TTL --%>
    <% cached LatestPhotoDataInFlickrStream %>
    <% include PhotoFeedFromFlickr %>
    <% end_cached %>

    <% include Footer %>
    </div>
    </body>
    </html>

    Looking forward to hearing what you have to say.

    Thanks.
    VWD.

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: Caching strategy for largely static site with small amount of dynamic content on some pages. Link to this post

    You don't need to bother wrapping any caching around static html areas (such as footer html) as that just increases the size of your cache without any major benefit. I'd suggest just find everywhere that is dynamic and partial cache those individual sections.

    <% cached 'navigation' %>
    ..
    <% end_cached %>
    ..
    <% cached 'pagecontent', LastEdited %>
    ..
    <% end_cached %>

    Things like $Form you don't want to cache anyway.

  • vwd
    Avatar
    Community Member
    158 Posts

    Re: Caching strategy for largely static site with small amount of dynamic content on some pages. Link to this post

    Thanks Will. I think you've helped me to understand a little better how SS caching works.

    So there isn't much advantage in caching any of the <% include %> blocks that are largely static?

    For example, my templates are broken up into smaller blocks eg. Nav, Head, Header, Footer as per code example below. Assembling these to serve up a page would cost some processing time I'd imagine. Caching these doesn't save much processing time, by helping to pre-assemble the smaller blocks to a full template?

    Thanks Will.

    VWD.

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: Caching strategy for largely static site with small amount of dynamic content on some pages. Link to this post

    For example, my templates are broken up into smaller blocks eg. Nav, Head, Header, Footer as per code example below. Assembling these to serve up a page would cost some processing time I'd imagine. Caching these doesn't save much processing time, by helping to pre-assemble the smaller blocks to a full template?

    Correct, caching those is not going to improve performance greatly as SS already 'caches' includes and generally templates (thats why you need to use ?flush=1 when making changes).

    Key is just to wrap anywhere that hits the database or other code which takes up processing time.

  • vwd
    Avatar
    Community Member
    158 Posts

    Re: Caching strategy for largely static site with small amount of dynamic content on some pages. Link to this post

    Thanks very much for clearing that up Will. I understand now.

    I really have to dig a little deeper then to investigate an intermittent performance issue with a site.

    Thanks.
    VWD.

    698 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.