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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Partial Caching


Go to End


5 Posts   970 Views

Avatar
vxd

Community Member, 19 Posts

15 May 2012 at 4:29pm

Edited: 15/05/2012 5:03pm

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

Avatar
vwd

Community Member, 166 Posts

20 May 2012 at 12:46am

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.

Avatar
Willr

Forum Moderator, 5523 Posts

20 May 2012 at 11:43am

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

Avatar
vwd

Community Member, 166 Posts

21 May 2012 at 7:23am

Hi Will,

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

Kind regards,
Prem.

Avatar
vxd

Community Member, 19 Posts

12 June 2012 at 12:19am

Thanks for that, so it should be

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