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?
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;
}
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.
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
We did this. It basicly creates a cached version of a page for each user.
Dave
Hello,
With donut cache you can also uncache certain parts of the page. This can be done with an html.action:
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
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.