Copied to clipboard

Flag this post as spam?

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


  • Patrick 33 posts 82 karma points
    Jun 19, 2014 @ 15:02
    Patrick
    0

    caching a partial view

    I am trying to implement cache on a partial view.
    According to some examples I should be able to use:

    @Html.CachedPartial("breadCrumbs", Model.Content, 3600)

    To cache the partial view which I would normally call by:

    @Html.Partial("breadCrumbs")

    However this doesn't return anything not even an error.
    Any idea what I am doing wrong?

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jun 19, 2014 @ 15:43
    Dennis Aaen
    0

    Hi Patrick,

    I just tried code that you´re talking about, on the Umbraco 7.1.4 starter kit, I created a basic breadcrumb from the Umbraco razor snippets.

    And then try to to the master layout:

    @Html.CachedPartial("BreadCrumb", Model.Content, 3600)

    And it works just fine, be awre that if you are on frontpage it dosen´t show anything. But what I think that you should do is check that the partial view name is correct.

    Hope this helps,

    /Dennis

  • Torben Warberg Rohde 35 posts 89 karma points
    Jun 19, 2014 @ 22:46
    Torben Warberg Rohde
    100

    Make sure you read the very last part of this page after "however":

    http://our.umbraco.org/documentation/Reference/Mvc/partial-views

    I have to admit I'm not quite sure what the exact implications of this is. It sounds to me like if you pass two different models to CachedPartial (i.e. the page you wan't the breadcrumb for) you will get the same breadcrumb for both pages within the cache timespan... not sure though, so if anyone knows please correct.

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Jun 17, 2016 @ 11:33
    Dan Diplo
    0

    To clarify:

    @Html.CachedPartial("BreadCrumb", Model.Content, 3600)
    

    The above will cache the partial globally across your entire your site. The content will be derived from whatever the first page to request the partial is. This content then won't change until the timespan expires OR you publish any page on your site.

    If you want to cache a partial just for an individual page you need to call the overload and pass "true" to cache-by-page:

    @Html.CachedPartial("BreadCrumb", Model.Content, 3600, true)
    

    Note: Caching only happens if you are NOT in debug mode.

  • Patrick 33 posts 82 karma points
    Jun 20, 2014 @ 12:03
    Patrick
    0

    Thanks Dennis and Toben,

    Actually the code was correct, problem is it only started working after a publish at the back-end.

  • Markus Johansson 1914 posts 5761 karma points MVP c-trib
    Apr 13, 2015 @ 22:18
    Markus Johansson
    2

    Hi!

    My "issues" with the @Html.CachedPartial-method was that the content never got cached. Turned out that this was becuse i had the <compilation debug="true" ../>-setting in web.config. Changing this to debug="false" would activate the cache.

  • Simon Dingley 1470 posts 3427 karma points c-trib
    Jun 17, 2016 @ 09:44
    Simon Dingley
    0

    I've also recently got caught by this however on the flip side it creates another issue for me in development because setting <compilation debug="false" ... /> I can't also profile the page by adding umbDebug=true to the querystring for the page.

    Is there a way around this problem?

    Thanks, Simon

  • Heather Floyd 604 posts 1002 karma points MVP 5x c-trib
    Apr 07, 2016 @ 16:52
    Heather Floyd
    1

    FYI - Something I noticed...

    If you are used to doing this:

    @{ Html.RenderPartial("~/Views/Partials/Nav_Main.cshtml"); }
    

    You need to remember that the CachedPartial call requires the @ directly in front:

    @Html.CachedPartial("~/Views/Partials/Nav_Main.cshtml", Model, 300)
    
  • jakub hromada 8 posts 98 karma points
    Sep 13, 2019 @ 13:18
    jakub hromada
    0

    This is why I was getting the blank page. Thanks for sharing.

Please Sign in or register to post replies

Write your reply to:

Draft