Copied to clipboard

Flag this post as spam?

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


  • Guy Malfait 23 posts 74 karma points
    Feb 07, 2016 @ 22:09
    Guy Malfait
    0

    Macro inside document property: how often does it get executed?

    Hello ...

    this is possibly a stupid question, but I was wondering ... if you add a Macro to a Document Property of a page, does that Macro get called every time the page gets served, or only when the page is saved on the back-end?

    In case you're wondering ... I'm trying to create a dynamic Meta tag, which depends on Archetype data (also a document property). So, when I change the Archetype data, I want the meta tag Description to reflect these changes.

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Feb 14, 2016 @ 02:31
    Marc Goodson
    101

    Hi Guy

    The Macro executes everytime the page it is on is requested (rather than at the point of insertion in the backoffice) this is good, as the macro remains up-to-date when content changes throughout the system.

    The downside of this could be if the macro is complicated, executing it on every request could slow the site down.

    Therefore it is also possible to 'cache' macro output - if you look at the macro in the developer - macros section in the backoffice you can provide a number of seconds for which to cache the output of the macro for. Whenever a page is published in Umbraco the cache is broken. So you could cache the output of your Dynamic Meta Tag Macro Output, for 86400 seconds and the macro would run only once a day for the first person to visit - but if the underlying archetype data changes, the cache will be broken, and the next person who visits the site, will trigger the caching of the updated macro.

    If the macro output is specific to the page you are on (eg a breadcrumb macro) then you would need to tick the 'cache by page' box to prevent the same breadcrumb from being displayed on every page!!

  • Guy Malfait 23 posts 74 karma points
    Feb 15, 2016 @ 14:59
    Guy Malfait
    0

    Hi Marc, thanks for your very helpful response. One more question if I may, can I make the same apply to partial view macro's?

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Feb 16, 2016 @ 21:32
    Marc Goodson
    0

    Yes, Guy,

    A Partial View Macro, is a way to implement a Macro and so can take advantage of the caching / parameter settings in the back office.

    If you need to call a Partial View (that is not a Macro Partial) directly from your view then you can apply caching using:

    @Html.CachedPartial("MyPartialName", new MyModel(), 3600)
    
  • Guy Malfait 23 posts 74 karma points
    Feb 19, 2016 @ 20:08
    Guy Malfait
    0

    OK thx Marc

Please Sign in or register to post replies

Write your reply to:

Draft