Fixes: #U4-2044, #U4-2048

This commit is contained in:
Shannon Deminick
2013-04-04 21:57:41 +06:00
parent f747f69c62
commit 87c904cc96
10 changed files with 218 additions and 26 deletions

View File

@@ -0,0 +1,43 @@
using System;
using Umbraco.Core;
using Umbraco.Core.Cache;
namespace Umbraco.Web.Cache
{
/// <summary>
/// Handles Application cache invalidation/refreshing
/// </summary>
public sealed class ApplicationCacheRefresher : CacheRefresherBase<ApplicationCacheRefresher>
{
protected override ApplicationCacheRefresher Instance
{
get { return this; }
}
public override Guid UniqueIdentifier
{
get { return Guid.Parse(DistributedCache.ApplicationCacheRefresherId); }
}
public override string Name
{
get { return "Applications cache refresher"; }
}
public override void RefreshAll()
{
ApplicationContext.Current.ApplicationCache.ClearCacheItem(CacheKeys.ApplicationsCacheKey);
}
public override void Refresh(int id)
{
Remove(id);
}
public override void Remove(int id)
{
ApplicationContext.Current.ApplicationCache.ClearCacheItem(CacheKeys.ApplicationsCacheKey);
}
}
}

View File

@@ -21,7 +21,16 @@ namespace Umbraco.Web.Cache
public class CacheRefresherEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
{
//bind to application tree events
ApplicationTree.Deleted += ApplicationTreeDeleted;
ApplicationTree.Updated += ApplicationTreeUpdated;
ApplicationTree.New += ApplicationTreeNew;
//bind to application events
Application.Deleted += ApplicationDeleted;
Application.New += ApplicationNew;
//bind to user type events
UserType.Deleted += UserTypeDeleted;
UserType.New += UserTypeNew;
@@ -116,6 +125,35 @@ namespace Umbraco.Web.Cache
MediaService.Trashing += MediaServiceTrashing;
}
#region ApplicationTree event handlers
static void ApplicationTreeNew(ApplicationTree sender, System.EventArgs e)
{
DistributedCache.Instance.RefreshAllApplicationTreeCache();
}
static void ApplicationTreeUpdated(ApplicationTree sender, System.EventArgs e)
{
DistributedCache.Instance.RefreshAllApplicationTreeCache();
}
static void ApplicationTreeDeleted(ApplicationTree sender, System.EventArgs e)
{
DistributedCache.Instance.RefreshAllApplicationTreeCache();
}
#endregion
#region Application event handlers
static void ApplicationNew(Application sender, System.EventArgs e)
{
DistributedCache.Instance.RefreshAllApplicationCache();
}
static void ApplicationDeleted(Application sender, System.EventArgs e)
{
DistributedCache.Instance.RefreshAllApplicationCache();
}
#endregion
#region UserType event handlers
static void UserTypeUpdated(UserType sender, System.EventArgs e)
{

View File

@@ -35,6 +35,8 @@ namespace Umbraco.Web.Cache
#region Public constants/Ids
public const string ApplicationTreeCacheRefresherId = "0AC6C028-9860-4EA4-958D-14D39F45886E";
public const string ApplicationCacheRefresherId = "B15F34A1-BC1D-4F8B-8369-3222728AB4C8";
public const string TemplateRefresherId = "DD12B6A0-14B9-46e8-8800-C154F74047C8";
public const string PageCacheRefresherId = "27AB3022-3DFA-47b6-9119-5945BC88FD66";
public const string MemberCacheRefresherId = "E285DF34-ACDC-4226-AE32-C0CB5CF388DA";

View File

@@ -13,6 +13,20 @@ namespace Umbraco.Web.Cache
/// </summary>
internal static class DistributedCacheExtensions
{
#region Application tree cache
public static void RefreshAllApplicationTreeCache(this DistributedCache dc)
{
dc.RefreshAll(new Guid(DistributedCache.ApplicationTreeCacheRefresherId));
}
#endregion
#region Application cache
public static void RefreshAllApplicationCache(this DistributedCache dc)
{
dc.RefreshAll(new Guid(DistributedCache.ApplicationCacheRefresherId));
}
#endregion
#region User type cache
public static void RemoveUserTypeCache(this DistributedCache dc, int userTypeId)
{

View File

@@ -0,0 +1,43 @@
using System;
using Umbraco.Core;
using Umbraco.Core.Cache;
namespace Umbraco.Web.Cache
{
/// <summary>
/// Handles User type cache invalidation/refreshing
/// </summary>
public sealed class UserTypeCacheRefresher : CacheRefresherBase<UserTypeCacheRefresher>
{
protected override UserTypeCacheRefresher Instance
{
get { return this; }
}
public override Guid UniqueIdentifier
{
get { return Guid.Parse(DistributedCache.UserTypeCacheRefresherId); }
}
public override string Name
{
get { return "User type cache refresher"; }
}
public override void RefreshAll()
{
ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(CacheKeys.UserTypeCacheKey);
}
public override void Refresh(int id)
{
Remove(id);
}
public override void Remove(int id)
{
ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(CacheKeys.UserTypeCacheKey);
}
}
}

View File

@@ -263,6 +263,8 @@
</Compile>
<Compile Include="ApplicationContextExtensions.cs" />
<Compile Include="CacheHelperExtensions.cs" />
<Compile Include="Cache\ApplicationCacheRefresher.cs" />
<Compile Include="Cache\ApplicationTreeCacheRefresher.cs" />
<Compile Include="Cache\ContentTypeCacheRefresher.cs" />
<Compile Include="Cache\DataTypeCacheRefresher.cs" />
<Compile Include="Cache\DictionaryCacheRefresher.cs" />