Copied to clipboard

Flag this post as spam?

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


  • Graham Carr 277 posts 389 karma points
    Mar 18, 2014 @ 17:47
    Graham Carr
    0

    Partial View versus Razor Macro Scripts

    I have been thinking about Partial Views vs Razor macro scripts and how they differ and Doug gave a good description on the following link:

    http://our.umbraco.org/forum/developers/razor/44664-Confused-over-when-DynamicNodeList-is-returned?p=0#comment160691

    My real query is that Partial Views in Umbraco do not have caching options therefore does this not mean they are slower than Macro Scripts, or do they already have caching enabled via some other method?

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Mar 18, 2014 @ 23:02
    Sebastiaan Janssen
    0

    Both macroscripts and partial views are only querying cached content. The updates to partial view querying makes them faster than macroscripts actually (as those are now considered "obsolete" and haven't been optimized for a long time). To make it even better the exact same partial view querying can be used in partial view macros and as you may or may not now, macros can be configured to use extra caching so the query will only be done once and the result will be held in memory for the amount of time configured on the macro.

    Hope this helps!

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Mar 18, 2014 @ 23:13
    Dan Diplo
    2

    Partials can also be cached. You use the @Html.CachedPartial syntax eg.

    Html.CachedPartial("MyPartialName", new MyModel(), 3600)

    If you just want to access the current page model then you can just use:

    Html.CachedPartial("MyPartialName", Model.Content, 3600)

    or even

    Html.CachedPartial("MyPartialName", null, 3600)

    See bottom of http://our.umbraco.org/documentation/Reference/Templating/Mvc/partial-views

    The partial cache gets cleared any time any page is published, so you can effectively cache a partial for as long as you want.

Please Sign in or register to post replies

Write your reply to:

Draft