Copied to clipboard

Flag this post as spam?

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


  • Joe Codino 25 posts 125 karma points
    Mar 14, 2016 @ 09:35
    Joe Codino
    0

    Macro cache with url rewrite

    I have a macro loaded by a page where url is rewritten:

    <add name="contentRewrite" virtualUrl="^~/blog/(.*)/.*"
                    rewriteUrlParameter="ExcludeFromClientQueryString"
                    destinationUrl="~/post/?id=$1"
                    ignoreCase="true" />
    

    If I access the page (via blog/123 or via post/?id=123) the macro is cached the first time, then it will be the same for all others pages. Example:

    1. access blog/123 = post with id 123 is cached
    2. access blog/234 = post with id 123 is shown instead of 234

    I'm embedding the macro with this code:

    @Umbraco.RenderMacro("Post")
    

    Is there any option to tell the macro to cache by id?

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Mar 14, 2016 @ 11:35
    Dave Woestenborghs
    0

    Hi Joe,

    I see you don't pass any parameters to your macro and I suspect you set up caching for your macro.

    This means it will execute the first request to the macro and cache it. All other calls to the macro will render the cached result.

    Probably you will also get the value of the querystring "id" inside the macro code.

    If you set up your macro with a "id" parameter you can pass that in to your macro call.

    This way the macro will execute for each different querystring value. But will return the result from cache if you call the page with the same querystring again.

    Makes sense ?

    Dave

  • Joe Codino 25 posts 125 karma points
    Mar 14, 2016 @ 12:57
    Joe Codino
    100

    Thanks to your suggestion I've solved the problem. Here the solution for future reference:

    1. Add a parameter to the macro (under Developer > Macros > macro name > Parameters tab). Example: postId
    2. Embed the macro passing the querystring parameter, like this:

      @Umbraco.RenderMacro("Post", new { postId = Request["id"] })

    3. Check the "cache by page" option in macro

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Mar 14, 2016 @ 12:58
    Dave Woestenborghs
    0

    Nice you were able to solve it.

    Don't forge to mark the post as solved so others can find it as well.

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft