Don’t Fight The Framework – Further down the rabbit hole optimising Sitecore MVC Performance.

I figured I had put this little mini-series too bed with my posts on Strategies to optimise Sitecore MVC performance and Further strategies to optimise MVC performance, it seems not.

I was recently looking into the effect of the @Html.Sitecore().Controller(“”) @Html.Sitecore().Rendering(“{id}”) on the performance of a Sitecore MVC based solution. Here is what I found:

@Html.Sitecore().Controller(“”)

This does exactly what it says on the tin, it indeed calls a controller (NOT controller rendering) from within your codebase. This is fine and dandy if that is what you want to do, but do bear in mind, it has no caching options available, so you need to implement your cache manually in your controller.

@Html.Sitecore().Rendering(“{id}”)

This on the other hand doesn’t. I expected this method to call my rendering (similar to sc:Sublayout in Sitecore webforms) and respect the caching settings set on the rendering item defined at {id}. In short – it doesn’t, it appears right now (tested and confirmed on Sitecore 7.2 and 7.5) to ignore your caching settings and simply call the controller / view rendering every time. This of course can have a negative impact on performance in your solution.

Conclusion

I guess as is the case with all of these things, don’t assume. I have been seriously considering running a series about performance optimisation techniques on here, but the biggest key is that we as developers should aim to have a performance testing & enhancement sprint regularly within our projects.

A support ticket has gone in at this time to ascertain whether this is desired behaviour (it doesn’t seem to be to me) and if not, will hopefully result in a patch from the amazing guys in Sitecore support. I believe it would also be neat to extend the api so we could set the cache settings in code?, but that’s a battle for another day.

Advertisements

2 thoughts on “Don’t Fight The Framework – Further down the rabbit hole optimising Sitecore MVC Performance.

  1. Great post, didn’t know this too. But setting the cache for a rendering in code is very easy (similar like setting the datasource):

    @Html.Sitecore().Rendering(“{id}”, new { Cacheable = true, Cache_VaryByData = true })

    You can also define the other parameters which you can control via the definition item.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s