Copied to clipboard

Flag this post as spam?

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


  • Steve Smith 71 posts 151 karma points
    14 days ago
    Steve Smith
    0

    Question about Html.CachedPartial

    Hi guys,

    We're having some performance problems with our site, and we played around with caching some of our "expensive" partials with CachedPartial() - and noticed it seemed to provide some significant improvement in page load times.

    Just wondered if I could ask a couple of questions about this before we implement?

    We have set the cacheByPage option to true, and also introduced our own logic in to the contextualKeyBuilder property - because some of the partial views are used across multiple pages, and have content that may differ depending on language.

    My question is are these two cache key properties combined? (i.e. when building the cache key, does it use the page Url and the contextualKeyBuilder argument - or does one override the other?)

    Also, when cacheByPage is true - does the cache key include the full Url (including the domain), or is it based on something like the page node Id?

    Thank you,

    Steve.

  • Marc Goodson 1178 posts 7892 karma points MVP 5x c-trib
    1 week ago
    Marc Goodson
    0

    Hi Steve

    You can see the implementation of CachedPartial here:

    https://github.com/umbraco/Umbraco-CMS/blob/0886ada39c4651fcd0a8bec5bce4358972791c45/src/Umbraco.Web/HtmlHelperRenderExtensions.cs

    and how the Cache Key is built up.

    If Cache By Page is turned on, then this will be combined in the Cache key with your ContextualKeyBuilder logic.

    With Cache By Page turned on it is only using the Id of the page and not the Url in they key.

    (Probably an oversight from when variants was introduced, eg the cache key should include the culture string too! - I made a similar fix for Macros: https://github.com/umbraco/Umbraco-CMS/pull/7555/files - we probably need to do the same for partials!)

    Anyway in the meantime, if you include the current culture in your contextual key, combined with the id from the Cache By Page being set to true, that will probably cover your needs?

    regards

    Marc

  • Steve Smith 71 posts 151 karma points
    1 week ago
    Steve Smith
    0

    Thank you Marc.

    We've added our own custom key which includes culture (and because we're using nested content/content blocks - the appropriate key for the content block).

    Although in-page - many of our partial views are actually rendered via a surface controller for maintainability purposes (i.e. so the logic is all in the controller, leaving the view files just for presentation). So I've also been working on how to cache them (and more importantly, how to clear that cache after a publish event) - successfully so far.

    Now to see whether it helps with performance and stability :)

    Steve.

  • Marc Goodson 1178 posts 7892 karma points MVP 5x c-trib
    1 week ago
    Marc Goodson
    0

    Cool, fingers crossed!

    I put a new PR here so that CachedPartial should always cache by culture... as I can see it would be an easy mistake to make on a site with variants...

    https://github.com/umbraco/Umbraco-CMS/pull/8348

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft