Copied to clipboard

Flag this post as spam?

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


  • TikTakToe 60 posts 102 karma points
    May 15, 2015 @ 12:02
    TikTakToe
    0

    donut cache and custom content after login

    hi, quick question - i have 'public' content in my website, donut cache applied - however, when a member logs in, i want to display custom content - however, donut is supplying the cache version. not wanting to blow the cache when a member logs in, the only thing i can think to do is add a q$ param to force different content. however, i'd have to persist that across all pages?

    anyone have a good solution to this or am i missing something obvious?

    thanks

    Ian

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    May 15, 2015 @ 13:15
    Dave Woestenborghs
    1

    We did this. It basicly creates a cached version of a page for each user.

    public override string GetVaryByCustomString(System.Web.HttpContext context, string custom)
            {          
                string result = base.GetVaryByCustomString(context, custom);
    
                if (string.IsNullOrEmpty(custom))
                {
                    return result;
                }
    
                result = string.Empty;
    
                var keys = custom.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList();
    
                if (keys.Contains(Caching.VarByCustomKeys.Url))
                {
                    result += string.Format("url={0};", context.Request.Url.AbsoluteUri);
                }
    
                if (keys.Contains(Caching.VarByCustomKeys.User))
                {
                    if (Member.IsLoggedOn())
                    {
                        result += string.Format("user={0};", Member.CurrentMemberId());
                    }
                }
    
                // handle preview mode caching
                if (UmbracoContext.Current.InPreviewMode)
                {
                    // store timestamp on first request
                    var ticks = DateTime.Now.Ticks;
                    if (HttpContext.Current.Items.Contains("ticks"))
                    {
                        ticks = (long)HttpContext.Current.Items["ticks"];
                    }
                    else
                    {
                        HttpContext.Current.Items.Add("ticks",ticks);
                    }
    
                    // cache by page id and timestamp
                    result += string.Format("preview={0};date={1};", UmbracoContext.Current.PageId, ticks);
                }
    
                return result;
            }

    Dave

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    May 26, 2015 @ 18:20
    Jeroen Breuer
    0

    Hello,

    With donut cache you can also uncache certain parts of the page. This can be done with an html.action:

    @Html.Action("ShowDates", "Newsoverview", true)

    The third parameter says exclude from parent cache. So the route hijacked controller and view are cached, but all logic done in the html action and it's view isn't. You can find an example in the best practises.

    https://github.com/jbreuer/Hybrid-Framework-for-Umbraco-v7-Best-Practises/blob/master/Umbraco.Site/Views/NewsOverview.cshtml#L76

    https://github.com/jbreuer/Hybrid-Framework-for-Umbraco-v7-Best-Practises/blob/master/Umbraco.Extensions/Controllers/NewsoverviewController.cs#L35

    So you can put the custom content for the member in the html.action so that doesn't get cached. That's the whole principle of Donut Cache.

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft