Copied to clipboard

Flag this post as spam?

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


  • James Drever 118 posts 149 karma points
    Oct 12, 2011 @ 12:34
    James Drever
    0

    renderpage and caching

    I'm using an inline Razor macro which attempts to call one of two other Razor macos using renderpage, dependent on checking a cookie:

    <umbraco:Macro runat="server" language="cshtml">
      @{  HttpCookie membersCookie = new HttpCookie("FSCMembersPreview");
    membersCookie = Request.Cookies["FSCMembersPreview"];
    // Read the cookie information and display it.
    if (membersCookie == null)
      
      @RenderPage("~/macroScripts/FSCListOfIndividualsFamiliesCourses.cshtml",Model.category);
      }
      else
      {
      @RenderPage("~/macroScripts/FSCListOfIndividualsFamiliesCoursesMembersPreview.cshtml",Model.category);  
      }
      }
    </umbraco:Macro>

    Which works fine, but the two razor scripts being called aren't being cached, & I really really need them to be.  Does anyone know of a way of calling a Razor script inline in thie way and it using the cache?  Wondering about RenderMacroContentbut can't see how it would work.
    Thanks! 

  • Rodion Novoselov 694 posts 859 karma points
    Oct 12, 2011 @ 13:27
    Rodion Novoselov
    0

    Hi. It seems that you can add Cache="..." attribute to your <umbraco:Macro> element to set cache duration, but I cannot see a way to have per-member cache for inline scripts. By the way, is there any reason not to simply convert it to a usual named macro? You will have all cache functionality and I beleive you also will improve readability of your template sources.

  • James Drever 118 posts 149 karma points
    Oct 12, 2011 @ 13:51
    James Drever
    0

    Thanks Rodion.  I'm not clear how I can convert it to a usual named macro given that its execution needs to be conditional on the result of the cookie check.  If I'm missing the blindingly obvious, let me know - I'll be delighted!

  • Rodion Novoselov 694 posts 859 karma points
    Oct 12, 2011 @ 14:04
    Rodion Novoselov
    0

    You can access the request cookies:

    1) through HttpContext.Current.Request.Cookies collection from anywhere;

    2) and, anyway, your Razor code is eventually compiled to the class inheriting from the DynamicNodeContext class, the WebPage class and so on. It doesn't depend on a way you use it - no matter it's an inline script or a macro. The only difference is where your script source comes from - from a separate file or straight from a string on the page. So you can use Request.Cookie[bla-bla-bla] and @RenderPage calls in your macro script as well as you do in your inline script.

Please Sign in or register to post replies

Write your reply to:

Draft