Was wondering if anyone had used donut caching on a load balance environment before. Was wondering if there's any additional setup that i need to do / worry about especially the cache clearing bit on a load balance environment. I have already got an event that clear off the cache whenever there is a publish/delete/etc.
Those events are not going to occur on all servers. Instead you should use the cache events as shown below (you should also be using ApplicationEventHandler)
namespace MyProject.Events
{
using System;
using Umbraco.Core.Cache;
using Umbraco.Core.Logging;
using Umbraco.Web.Cache;
using Umbraco.Core;
using DevTrends.MvcDonutCaching;
public class UmbracoEvents : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
CacheRefresherBase<PageCacheRefresher>.CacheUpdated += this.CachePageEvents_CacheUpdated;
CacheRefresherBase<DictionaryCacheRefresher>.CacheUpdated += this.CacheDictionaryEvents_CacheUpdated;
CacheRefresherBase<MediaCacheRefresher>.CacheUpdated += this.CacheMediaEvents_CacheUpdated;
}
private void CacheMediaEvents_CacheUpdated(MediaCacheRefresher sender, CacheRefresherEventArgs e)
{
ClearDonutOutputCache();
}
private void CacheDictionaryEvents_CacheUpdated(DictionaryCacheRefresher sender, CacheRefresherEventArgs e)
{
ClearDonutOutputCache();
}
private void CachePageEvents_CacheUpdated(PageCacheRefresher sender, CacheRefresherEventArgs e)
{
ClearDonutOutputCache();
}
private void ClearDonutOutputCache()
{
var cacheManager = new OutputCacheManager();
cacheManager.RemoveItems();
LogHelper.Info<UmbracoEvents>(string.Format("Donut Output Cache Cleared On Server:{0} AppDomain:{1}", Environment.MachineName, System.AppDomain.CurrentDomain.FriendlyName));
}
}
}
The reason is I've got a feed that update and publish a node every 20 minutes. So wanted to detect and exclude that node from clearing the cache if it's possible.
if (e.MessageType == MessageType.RefreshById)
{
var id = (int) e.MessageObject;
if (e.MessageType == MessageType.RefreshById)
{
var publishedNode = UmbracoContext.Current.ContentCache.GetById(id);
if (publishedNode != null)
{
contentType = publishedNode.DocumentTypeAlias;
}
}
if (!string.IsNullOrEmpty(contentType))
{
if (!contentType.InvariantEquals("MySpecialDocTypeAlias"))
{
ClearDonutOutputCache();
}
}
}
may need to be:
if (e.MessageType == MessageType.RefreshById)
{
var publishedNode = UmbracoContext.Current.ContentCache.GetById(e.MessageObject);
if (publishedNode != null)
{
contentType = publishedNode.DocumentTypeAlias;
}
}
if (!string.IsNullOrEmpty(contentType))
{
if (!contentType.InvariantEquals("MySpecialDocTypeAlias"))
{
ClearDonutOutputCache();
}
}
Is there any way to achieve Donut caching but not clear all cache items everytime we publish? Wont this cause an overhead on servers which are constantly publishing?
Donut caching on Load Balance environment
Hi All,
Was wondering if anyone had used donut caching on a load balance environment before. Was wondering if there's any additional setup that i need to do / worry about especially the cache clearing bit on a load balance environment. I have already got an event that clear off the cache whenever there is a publish/delete/etc.
Appreciate any help on this. Thanks
Yes lots of times, the clear events are key, what events are you using?
Hi Jeavon,
I'm using the below to clear off the cache. Do i need to change it for a load balance environment? Thanks
Those events are not going to occur on all servers. Instead you should use the cache events as shown below (you should also be using ApplicationEventHandler)
Thanks @Jeavon.
Nice. Thanks Jeavon ;)
Hey Jeavon,
Quick question, is there a way i can check for a certain document type to be excluded from the CachePageEvents_CacheUpdated?
Thanks
The reason is I've got a feed that update and publish a node every 20 minutes. So wanted to detect and exclude that node from clearing the cache if it's possible.
Thanks
Yes you can, something like this:
may need to be:
You're a superstar Jeavon ;)
Hey Jeavon quick question,
Have you came across a way to rebuild indexes on a distributed environments?
Eg when the Developer Section > Examine Management index gets rebuild on a single environment and it rebuilds on the rest of the environments
Can't find anything in the forum
Thanks
Hi JLon. Did you find a way to rebuild indexes in distributed environments?
Hey Tommy,
Just saw this. You mean rebuild the entire indexes on individual load balancing environment?
Reminded me, I did build a simple tool for this, it's on GitHub (no package currently) https://github.com/CrumpledDog/ExamineDistributedDashboard
Looking forward to trying this out - it's something I've had on my list for a long time and never had the chance to investigate further! Thanks
Hi,
Is there any way to achieve Donut caching but not clear all cache items everytime we publish? Wont this cause an overhead on servers which are constantly publishing?
Poornima
is working on a reply...