Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Karl Kopp 121 posts 227 karma points
    Aug 26, 2014 @ 10:45
    Karl Kopp
    0

    Html.CachedPartial not working

    Hi All!

    I've been playing around with some performance enhancements in an Umbraco install. One of the option I am playing with is replacing calls to Html.RenderPartial() with calls to Html.CachedPartial(). I started on a 7.1.4 site, but each partial returned a blank. I grabbed a clean 7.1.5 install with the responsive starter kit, and replaced:

    Html.RenderPartial("umbNewsOverviewWidget"); 
    

    with

    Html.CachedPartial("umbNewsOverviewWidget", Model.Content, 20);
    

    in the umbHomePage.cshtml file, and it also returns a blank partial. Any ideas? Anyone got this working?

    Cheers!

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 26, 2014 @ 14:05
    Jeavon Leopold
    0

    Hi Karl,

    I am also seeing this issue on v7.1.6 and have reported it here.

    Jeavon

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 26, 2014 @ 15:56
    Jeavon Leopold
    102

    Hi Karl,

    After much debugging I discovered it was my mistake, in fact Html.CachedPartial is equivalent to Html.Partial not Html.RenderPartial so you just need to ensure you render like this

    @Html.CachedPartial("umbNewsOverviewWidget", Model.Content, 20);
    

    Jeavon

  • Karl Kopp 121 posts 227 karma points
    Aug 27, 2014 @ 00:08
    Karl Kopp
    0

    I wish I could give u 10 high fives :) Nice work - would be good to get the docs updated perhaps as they seem a little unclear?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 27, 2014 @ 00:16
    Dennis Aaen
    0

    Hi Karl,

    Have you seen this documentation about caching MVC Partial Views in Umbraco. If not then it can be found here: http://our.umbraco.org/documentation/Reference/Mvc/partial-views#Caching

    /Dennis

  • Karl Kopp 121 posts 227 karma points
    Aug 27, 2014 @ 01:00
    Karl Kopp
    0

    @Dennis - I had, but had syntax blindness :) I was changing the syntax, but not how I included the call in the page.

    One thing that I haven't worked out is how to use the query string as a key in the cache like you could do in the old macros. Is that possible?

  • Karl Kopp 121 posts 227 karma points
    Aug 27, 2014 @ 01:18
    Karl Kopp
    0

    Further to this, I've tried to bust the cache as follows:

    @Html.CachedPartial("MyMacro", Model.Content, 600, true, false, new ViewDataDictionary { { "page", pageNumber } })
    

    But this keeps showing the first page of a multiple page result. Surely there is a way to use a param as part of the cache key? Anyone???

    Cheers!

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 27, 2014 @ 10:40
    Jeavon Leopold
    0

    Hi Karl,

    I don't think so, if you read the last paragraph

    "So you can specify to cache by member and/or by page and also specify additional view data to your partial view. However, if your view data is dynamic (meaning it could change per page request) the cached output will still be returned. This same principle applies if the model you are passing in is dynamic. Please be aware of this: if you have a different model or viewData for any page request, the result will be the cached result of the first execution."

    Have you considered using Donut caching? I would highly recommend you watch the video of this session from CodeGarden 2014 where several Umbraco caching options (including Donut) are considered in detail.

    Jeavon

  • Karl Kopp 121 posts 227 karma points
    Aug 28, 2014 @ 02:50
    Karl Kopp
    0

    Thanks Jeavon - I've already seen the video, great video!. In a number of cases use a CDN like CloudFlare ($25/mth) + a publish event handler to purge the CDN cache. But, that said, the ability to cache at multiple layers is always beneficial. It was a great feature of v4, and would be awesome to have as part of v7. Even if you used the ViewDataDictionary as cache keys and not worry about the model, that would be a great outcome... pulling a feature out, especially one that directly impacts performance, is a bit of a worry to me at least...

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 29, 2014 @ 10:59
    Jeavon Leopold
    0

    Having had a good look at how the macro caching works, I think it would be possible to do this. I suggest you raise a feature request on YouTrack.

Please Sign in or register to post replies

Write your reply to:

Draft