Reputation: 3203
I have been tasked with finding out which of our Sublayouts have caching turned on. I'm not talking about the caching on the sublayout - I mean the caching on each individual instance of that sublayout as set in the rendering parameters.
Here's what I currently do:
My problem is that the 'Cachable' setting I'm seeing is the one set in the Sublayout (under Layout > Sublayouts in Sitecore) and not the one I set on the instance of that sublayout on my item (My Item > Presentation > Details > click control)
My code is written on a stand alone
Number 1 is no problem - here's what I do for each item:
2)
RenderingReference[] renderings = item.Visualization.GetRenderings(Sitecore.Context.Device, true);
3)
foreach (RenderingReference r in renderings)
4)
bool cacheable = r.RenderingItem.Caching.Cacheable;
It seems I'm missing a step where I get the rendering parameters specific to each sublayout. However, from the guides I have read it seems you need the sublayout itself to get access to these parameters. I cannot find a way to get a sublayout from an item or rendering reference (maybe with good reason?). Can anyone help me progress?
Getting rendering parameters from sublayout
Upvotes: 2
Views: 1415
Reputation: 31435
Another way to determine this would be to go to the /sitecore/admin/stats.aspx
page and check the number of renderings vs. cache hits. So look at the rows that start with Sublayout : and see if the Cache column is greater than 0. If its greater than 0 then those are the times a cached entry was loaded. If its always 0 then its not set to cache.
Upvotes: 2
Reputation: 13141
I have been tasked with finding out which of our Sublayouts have caching turned on. I'm not talking about the caching on the sublayout - I mean the caching on each individual instance of that sublayout as set in the rendering parameters.
By referencing r.RenderingItem
, you are accessing the rendering's definition item, not the 'instance' of that Sublayout in the presentation details.
To get the caching for each instance of the presentation details, you can use:
RenderingReference[] renderings = Sitecore.Context.Item.Visualization.GetRenderings(Sitecore.Context.Device, true);
foreach (var renderingReference in renderings)
{
// var isDefinitionItemCacheable = renderingReference.RenderingItem.Caching.Cacheable;
var isInstanceCacheable = renderingReference.Settings.Caching.Cacheable;
}
Or..
var sublayout = Parent as Sublayout;
if (sublayout != null)
{
var cacheable = sublayout.Cacheable;
}
Upvotes: 4