Jump to:

23379 Posts in 18298 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Partial Caching

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: 459 Views
  • vxd
    Avatar
    Community Member
    16 Posts

    Partial Caching Link to this post

    I am using partial caching for the main content block of main template.

    This is what I have in the template file

    <% cached 'database', LastEdited %>
    $Content
    <% end_cached %>

    The main template is used on most of the page.

    If I visit "about us" it will display the content for about us, then when I visit "Services" it will display the content from the "about us" page

    It's cached the content from "About Us" and displaying the "About Us" content on all of the pages sharing the same template.

    How do I get this to work properly so it displays the content of it's own page

    Thanks

  • vwd
    Avatar
    Community Member
    158 Posts

    Re: Partial Caching Link to this post

    Hi VXD,

    Try adding 'URLSegment' to the cache key. Ie.

    <% cached 'database', LastEdited, URLSegment %>
       $Content
    <% end_cached %>

    There is an explanation of this in the article on SilverStripe by Phillip Krenn.

    Hope this helps.

    VWD.

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Partial Caching Link to this post

    ID might be a safer key than URLSegment as you'll have multiple pages with the same URLSegment (nested urls).

  • vwd
    Avatar
    Community Member
    158 Posts

    Re: Partial Caching Link to this post

    Hi Will,

    Thanks for that suggestion - so $URLSegment is not unique across a site, and obviously $ID is.

    Kind regards,
    Prem.

  • vxd
    Avatar
    Community Member
    16 Posts

    Re: Partial Caching Link to this post

    Thanks for that, so it should be

    <% cached 'database', LastEdited, ID %>
    $Content
    <% end_cached %>

    459 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.