using System;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Models;
using Umbraco.Core.Sync;
using umbraco;
using umbraco.cms.businesslogic.web;
using umbraco.interfaces;
using umbraco.presentation.cache;
namespace Umbraco.Web.Cache
{
///
/// PageCacheRefresher is the standard CacheRefresher used by Load-Balancing in Umbraco.
///
///
/// If Load balancing is enabled (by default disabled, is set in umbracoSettings.config) PageCacheRefresher will be called
/// everytime content is added/updated/removed to ensure that the content cache is identical on all load balanced servers
///
public class PageCacheRefresher : TypedCacheRefresherBase
{
protected override PageCacheRefresher Instance
{
get { return this; }
}
///
/// Gets the unique identifier of the CacheRefresher.
///
/// The unique identifier.
public override Guid UniqueIdentifier
{
get
{
return new Guid(DistributedCache.PageCacheRefresherId);
}
}
///
/// Gets the name of the CacheRefresher
///
/// The name.
public override string Name
{
get { return "Page Refresher"; }
}
///
/// Refreshes all nodes in umbraco.
///
public override void RefreshAll()
{
content.Instance.RefreshContentFromDatabaseAsync();
base.RefreshAll();
}
///
/// Refreshes the cache for the node with specified id
///
/// The id.
public override void Refresh(int id)
{
ApplicationContext.Current.ApplicationCache.ClearPartialViewCache();
content.Instance.UpdateDocumentCache(id);
DistributedCache.Instance.ClearAllMacroCacheOnCurrentServer();
DistributedCache.Instance.ClearXsltCacheOnCurrentServer();
base.Refresh(id);
}
///
/// Removes the node with the specified id from the cache
///
/// The id.
public override void Remove(int id)
{
ApplicationContext.Current.ApplicationCache.ClearPartialViewCache();
content.Instance.ClearDocumentCache(id);
DistributedCache.Instance.ClearAllMacroCacheOnCurrentServer();
DistributedCache.Instance.ClearXsltCacheOnCurrentServer();
base.Remove(id);
}
public override void Refresh(IContent instance)
{
ApplicationContext.Current.ApplicationCache.ClearPartialViewCache();
content.Instance.UpdateDocumentCache(new Document(instance));
DistributedCache.Instance.ClearAllMacroCacheOnCurrentServer();
DistributedCache.Instance.ClearXsltCacheOnCurrentServer();
base.Refresh(instance);
}
public override void Remove(IContent instance)
{
ApplicationContext.Current.ApplicationCache.ClearPartialViewCache();
content.Instance.ClearDocumentCache(new Document(instance));
DistributedCache.Instance.ClearAllMacroCacheOnCurrentServer();
DistributedCache.Instance.ClearXsltCacheOnCurrentServer();
base.Remove(instance);
}
}
}