Copied to clipboard

Flag this post as spam?

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


  • Martin 114 posts 313 karma points
    Sep 12, 2015 @ 15:01
    Martin
    0

    Cache by page false vs. true, and caching refresh

    Hi,

    When using macro caching or @Html.CachedPartial, what is the difference whether "Cache by page" is true or is false?

    As I understand it, if the macro or partial view would be used on one page only, there would be no difference. It this correct? That is, is "Cache by page" only useful if the macro or partial view is used in two or more pages?

    And, will the cache auto-refresh itself when the cache period time runs out? Or will it wait for a active page visit, i.e., if caching time is set to 1 hour, and a person A visits the page 2.00 pm., and then again 3.30 pm. (we assume no other visitors at all), would the first cache be at time 2 pm. and the new cache at 3pm or 3.30 pm?

    Best regards, Martin

  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Sep 13, 2015 @ 01:15
    Marc Goodson
    100

    Hi Martin,

    Yes, 'cache by page' will add a version of the output of the macro to the cache for each page.

    So if the Macro produces the exact same html on every page, you shouldn't tick 'cache by page',

    But in the case of for example, a macro producing a Breadcrumb, you would want to tick 'cache by page', because otherwise the same breadcrumb would appear on each page, which would be wrong.

    Whenever any item is published the entire macro cache is cleared.

    In terms of the cache period, it will be the next request to the page, that will check to see if the item's cache period has expired, so in your example, the new cache would be at 3:30pm

  • Martin 114 posts 313 karma points
    Sep 13, 2015 @ 07:39
    Martin
    0

    Thanks Marc!

    As a follow up question, do you know a good way to implement a server side re-caching i.e., to make the cache update itself automatically when the cache period runs out. For example, would it be possible to set an 1 hour "auto-recache"?

  • Martin 114 posts 313 karma points
    Sep 13, 2015 @ 10:26
    Martin
    0

    I just tested the breadcrumb idea. but I don't get the cache to work.

    Uncached:

    @Html.Partial("Breadcrumb", @Model.Content) 
    

    Cached:

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

    With this markup the "Cache by page" is default false, that is, the breadcrumb should be the same on all pages but it still work as the Uncached. So I wonder if I also need to enable caching somewhere else in Umbraco

  • Tom Van Rompaey 38 posts 136 karma points
    Sep 13, 2015 @ 12:21
    Tom Van Rompaey
    2

    Make sure debug is set to false in the web.config, otherwise it won't work.

    More info: http://issues.umbraco.org/issue/U4-5940

  • Martin 114 posts 313 karma points
    Sep 13, 2015 @ 14:14
    Martin
    0

    Thanks alot. That's explains it.

  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Sep 17, 2015 @ 21:03
    Marc Goodson
    0

    Hi Martin

    with the 1 hour auto-refresh, what are you trying to achieve ?

    ie are you thinking that you want the cache to run out after an hour, then get updated values, and put itself back in the cache, ready for the next request, even if no request is made ?

    There are tricks outside of Umbraco with the .net framework for caching objects with a cache expiry call back function, that fires when the item disappears from cache; but this is different to Umbraco Macro caching.

    I suppose you could schedule a task, to request a url that would cause the Macro cache to be rebuilt each hour:

    ie in umbracoSettings:

      <scheduledTasks>
        <!-- add tasks that should be called with an interval (seconds) -->
       <task log="true" alias="tcachebreak" interval="3600" url="http://localhost/umbraco/urlofpagewithmacro"/>
      </scheduledTasks>
    
  • Martin 114 posts 313 karma points
    Sep 18, 2015 @ 06:26
    Martin
    0

    Thanks for you response Marc. Basically, what I was aiming at was to ensure that some "time heavy" partial always stays cached so that a visitor never will expires loading time more that 5-6 seconds. But I will have a go with the scheduled tasks.

    By the way, my current web host has a 3 hour idle application pool shut down, that is, during night I don't have no visitors and the first one in the morning will have to wait for the pool start-up (takes to long). My web host recommended setting up a cron-job to ensure that the pool never shuts down due to the maximum idle time span.

    Would you say that a scheduled task would would be sufficient for such a "cron job" ? I mean, will a scheduled task trigger page request at my web host?

Please Sign in or register to post replies

Write your reply to:

Draft