Jump to:

22977 Posts in 11806 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Partial caching doesn't re-cache on template change.

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: 570 Views
  • vwd
    Avatar
    Community Member
    158 Posts

    Partial caching doesn't re-cache on template change. Link to this post

    Hi,

    I've implemented partial caching on a site, and I'm noticing significant performance gains already.

    I notice however that when the template within the partial cache block is changed the cache doesn't refresh as the documentation says it should. The only thing that causes a refresh is when the explicitly provided key changes.

    Eg.

    <% cached 'MyCachedBlock', SiteConfig.LastEdited %>
    <div>
    $SiteConfig.tagline
    <div>
    <% end_cached %>

    Whenever I change the template within the partial cache block, the cache doesn't refresh,. It only refreshes when I modify SiteConfig. Even a ?flush=all has no effect

    This happens for all page templates as well as module templates. Interestingly, in cache blocks which don't have an explicit key, a ?flush=all does refresh the cache.

    Anyone else seen this?

    Kind regards,
    VWD.

  • vwd
    Avatar
    Community Member
    158 Posts

    Re: Partial caching doesn't re-cache on template change. Link to this post

    A bit more on this... whilst the partial caching still doesn't re-cache on a template change, it does when I perform a ?flush=all now.

    I realised that the cache block was nested within another with the same key...

    <% cached 'OuterCachedBlock', SiteConfig.LastEdited %>
       <div id="$UniqueID">
          <% cached 'MyCachedBlock', SiteConfig.LastEdited %>
             <div id="inner-$UniqueID">
                $SiteConfig.tagline
             </div>
          <% end_cached %>
       </div>
    <% end_cached %>

    When I modify the code to uncache around the nested block, SS recaches on a ?flush=all but still not on a template change.

    Eg.

    <% cached 'OuterCachedBlock', SiteConfig.LastEdited %>
       <div>
          <h3>$SiteConfig.PhoneNumber</h3>
          <% uncached %>
             <div id="$UniqueID">
                <% cached 'MyCachedBlock', SiteConfig.LastEdited %>
                   <div id="inner-$UniqueID">
                      $SiteConfig.tagline
                   </div>
                <% end_cached %>
             </div>
          <% end_uncached %>
       </div>
    <% end_cached %>

    Any ideas?

    Thank you.
    VWD.

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Partial caching doesn't re-cache on template change. Link to this post

    I get around this by including this in my _config.php

    if(isset($_REQUEST['flush'])) {
       SS_Cache::set_cache_lifetime('any', -1, 100);
    }

    Whether you are using partial caching or not, you always need to flush if you make template changes.

  • vwd
    Avatar
    Community Member
    158 Posts

    Re: Partial caching doesn't re-cache on template change. Link to this post

    Thanks Will.

    So does that mean the section "Cache blocks and template changes" in the documentation is inaccurate? Or do I read incorrectly?

    How does including the statement...

    if(isset($_REQUEST['flush'])) {
    SS_Cache::set_cache_lifetime('any', -1, 100);
    }

    ... differ in behaviour from the normal explicit cache flushing functionality?

    Thanks Will.

    VWD.

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