Files
Umbraco-CMS/src/Umbraco.Web/Strategies/Publishing/UpdateCacheAfterPublish.cs
Shannon Deminick cb3ac17f43 Ensures tree is synced on bulk publish, fixes Dimming on the content node. Starts adding ability to
make distributed calls that are strongly typed and can do more than one at a time.
2013-02-12 04:47:36 +06:00

80 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Umbraco.Core.Publishing;
using Umbraco.Web.Cache;
using umbraco;
using umbraco.cms.businesslogic.web;
using umbraco.interfaces;
using umbraco.presentation.cache;
using UmbracoSettings = Umbraco.Core.Configuration.UmbracoSettings;
namespace Umbraco.Web.Strategies.Publishing
{
/// <summary>
/// Represents the UpdateCacheAfterPublish class, which subscribes to the Published event
/// of the <see cref="PublishingStrategy"/> class and is responsible for doing the actual
/// cache refresh after a content item has been published.
/// </summary>
/// <remarks>
/// This implementation is meant as a seperation of the cache refresh from the ContentService
/// and PublishingStrategy.
/// This event subscriber will only be relevant as long as there is an xml cache.
/// </remarks>
public class UpdateCacheAfterPublish : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
PublishingStrategy.Published += PublishingStrategy_Published;
}
void PublishingStrategy_Published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
{
if (e.PublishedEntities.Any())
{
if (e.IsAllRepublished)
{
UpdateEntireCache();
return;
}
if (e.PublishedEntities.Count() > 1)
{
UpdateMultipleContentCache(e.PublishedEntities);
}
else
{
var content = e.PublishedEntities.FirstOrDefault();
UpdateSingleContentCache(content);
}
}
}
/// <summary>
/// Refreshes the xml cache for all nodes
/// </summary>
private void UpdateEntireCache()
{
DistributedCache.Instance.RefreshAllPageCache();
}
/// <summary>
/// Refreshes the xml cache for nodes in list
/// </summary>
private void UpdateMultipleContentCache(IEnumerable<IContent> content)
{
DistributedCache.Instance.RefreshPageCache(content);
}
/// <summary>
/// Refreshes the xml cache for a single node
/// </summary>
private void UpdateSingleContentCache(IContent content)
{
DistributedCache.Instance.RefreshPageCache(content.Id);
}
}
}