Converts the media cache refresher to be a json cache refresher since it was impossible before to have media cache

cleared when media was deleted. Created base classes for cache refreshers, we now have a new event - CacheUpdated
which can now be used by code to execute on each individual server when any cache refresher is updated. Listening to events
normally only fire on the individual server so if people are wanting to refresh their own cache there was previously no way
to do that.
This commit is contained in:
Shannon Deminick
2013-03-21 22:53:58 +06:00
parent ab8b0f4ebb
commit 5f242aa3f6
15 changed files with 442 additions and 198 deletions

View File

@@ -120,16 +120,7 @@ namespace Umbraco.Web.Cache
#endregion
#region Media Cache
/// <summary>
/// Refreshes the cache amongst servers for a media item
/// </summary>
/// <param name="dc"></param>
/// <param name="mediaId"></param>
public static void RefreshMediaCache(this DistributedCache dc, int mediaId)
{
dc.Refresh(new Guid(DistributedCache.MediaCacheRefresherId), mediaId);
}
/// <summary>
/// Refreshes the cache amongst servers for a media item
/// </summary>
@@ -137,7 +128,8 @@ namespace Umbraco.Web.Cache
/// <param name="media"></param>
public static void RefreshMediaCache(this DistributedCache dc, params IMedia[] media)
{
dc.Refresh(new Guid(DistributedCache.MediaCacheRefresherId), x => x.Id, media);
dc.RefreshByJson(new Guid(DistributedCache.MediaCacheRefresherId),
MediaCacheRefresher.SerializeToJsonPayload(media));
}
/// <summary>
@@ -145,6 +137,11 @@ namespace Umbraco.Web.Cache
/// </summary>
/// <param name="dc"></param>
/// <param name="mediaId"></param>
/// <remarks>
/// Clearing by Id will never work for load balanced scenarios for media since we require a Path
/// to clear all of the cache but the media item will be removed before the other servers can
/// look it up. Only here for legacy purposes.
/// </remarks>
public static void RemoveMediaCache(this DistributedCache dc, int mediaId)
{
dc.Remove(new Guid(DistributedCache.MediaCacheRefresherId), mediaId);
@@ -157,8 +154,10 @@ namespace Umbraco.Web.Cache
/// <param name="media"></param>
public static void RemoveMediaCache(this DistributedCache dc, params IMedia[] media)
{
dc.Remove(new Guid(DistributedCache.MediaCacheRefresherId), x => x.Id, media);
dc.RemoveByJson(new Guid(DistributedCache.MediaCacheRefresherId),
MediaCacheRefresher.SerializeToJsonPayload(media));
}
#endregion
#region Macro Cache
@@ -173,16 +172,6 @@ namespace Umbraco.Web.Cache
dc.RefreshAll(new Guid(DistributedCache.MacroCacheRefresherId), false);
}
/// <summary>
/// Refreshes the cache amongst servers for a macro item
/// </summary>
/// <param name="dc"></param>
/// <param name="macroId"></param>
public static void RefreshMacroCache(this DistributedCache dc, int macroId)
{
dc.Refresh(new Guid(DistributedCache.MacroCacheRefresherId), macroId);
}
/// <summary>
/// Refreshes the cache amongst servers for a macro item
/// </summary>
@@ -192,20 +181,11 @@ namespace Umbraco.Web.Cache
{
if (macro != null)
{
dc.Refresh(new Guid(DistributedCache.MacroCacheRefresherId), macro1 => macro1.Id, macro);
dc.RefreshByJson(new Guid(DistributedCache.MacroCacheRefresherId),
MacroCacheRefresher.SerializeToJsonPayload(macro));
}
}
/// <summary>
/// Removes the cache amongst servers for a macro item
/// </summary>
/// <param name="dc"></param>
/// <param name="macroId"></param>
public static void RemoveMacroCache(this DistributedCache dc, int macroId)
{
dc.Remove(new Guid(DistributedCache.MacroCacheRefresherId), macroId);
}
/// <summary>
/// Removes the cache amongst servers for a macro item
/// </summary>
@@ -215,7 +195,8 @@ namespace Umbraco.Web.Cache
{
if (macro != null)
{
dc.Remove(new Guid(DistributedCache.MacroCacheRefresherId), macro1 => macro1.Id, macro);
dc.RemoveByJson(new Guid(DistributedCache.MacroCacheRefresherId),
MacroCacheRefresher.SerializeToJsonPayload(macro));
}
}
@@ -228,7 +209,8 @@ namespace Umbraco.Web.Cache
{
if (macro != null && macro.Model != null)
{
dc.Remove(new Guid(DistributedCache.MacroCacheRefresherId), macro1 => macro1.Model.Id, macro);
dc.RemoveByJson(new Guid(DistributedCache.MacroCacheRefresherId),
MacroCacheRefresher.SerializeToJsonPayload(macro));
}
}
#endregion