Jump to:

23450 Posts in 18899 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Partial Caching SS3

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: 403 Views
  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Partial Caching SS3 Link to this post

    I'm not sure if this is an issue with partial caching or my understanfing of it. If I put a cached block in my Layout/Page.ss it caches the first content loaded for that pagetype and not for that specific page. So any page of that pagetype shows the same content unless I flush the cache

  • simon_w
    Avatar
    Forum Moderator
    471 Posts

    Re: Partial Caching SS3 Link to this post

    Have a look at the documentation for partial caching.

    If you don't provide a key that is specific to that page, then the cache block will be the same across pages.

  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Re: Partial Caching SS3 Link to this post

    Just wondering if useing something like <% cached $URLSegment, LastEdited %> is the best way to handle partial caching on pages or should the key be genreated from a cusotm function?

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Partial Caching SS3 Link to this post

    Depends on what you're doing, but I find that most page types which are either pulling the current page's $Content, $Title etc, or from another page, or generating a menu, this key seems to work well:

    <% cached 'mycachekey', ID, List(Page).max(LastEdited) %>
    ... content goes here
    <% end_cached %>

    The cache is invalidated by page ID, and whether any Page or subclass on the site has been modified.

    Obviously if you have a lot of special template controls, or time based data inside the cacheblock, you'll want to generate the key from a custom function instead.

    Sean

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