Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

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

Partial caching doesn't re-cache on template change.


Go to End
Reply


4 Posts   863 Views

Avatar
vwd

Community Member, 160 Posts

18 May 2012 at 9:33am

Edited: 18/05/2012 3:40pm

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.

Avatar
vwd

Community Member, 160 Posts

18 May 2012 at 4:03pm

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.

Avatar
Willr

Forum Moderator, 5517 Posts

20 May 2012 at 12:00pm

Edited: 20/05/2012 12:01pm

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.

Avatar
vwd

Community Member, 160 Posts

21 May 2012 at 11:31am

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.