Adds another method of distributed cache syncing using a custom json payload. this is necessary for things like ContentType cache

updates especially when deleting one since we require all sorts of Ids from the object but the object will be deleted by the time
the request reaches other servers so instead we create a json payload to send to other servers which contains all information necessary
to refresh/clear the cache on the other servers. This will probably be the preferred way going forward to handle cache refreshing.
With this in place, when removing a conent type cache is removed based on events.
This also adds a 'class' generic argument constraint to the repository base classes to guarantee we can do null checks and then we also
fix a null check on RepositoryBase. Updates the Entity class to properly support tracking properties - this now allows us to determine if
an entity was new, which is now used to ensure we don't re-update all of the content cache when a new content type is created.
Have also changed the deletion and creation of document types to use the new API, this allows for a lot less processing and streamlining how
all cache is invalidated. Fixes the construction of a new Template and Content Type in the v6 api and ensures that default values are set - #U4-1972, #U4-1971
This commit is contained in:
Shannon Deminick
2013-03-21 08:38:18 +06:00
parent c5a0da6aa5
commit 52f05612ad
21 changed files with 584 additions and 167 deletions

View File

@@ -12,6 +12,7 @@ namespace Umbraco.Web.Cache
/// </summary>
public static class DistributedCacheExtensions
{
#region User cache
public static void RemoveUserCache(this DistributedCache dc, int userId)
{
dc.Remove(new Guid(DistributedCache.UserCacheRefresherId), userId);
@@ -20,8 +21,10 @@ namespace Umbraco.Web.Cache
public static void RefreshUserCache(this DistributedCache dc, int userId)
{
dc.Refresh(new Guid(DistributedCache.UserCacheRefresherId), userId);
}
}
#endregion
#region Template cache
/// <summary>
/// Refreshes the cache amongst servers for a template
/// </summary>
@@ -40,8 +43,10 @@ namespace Umbraco.Web.Cache
public static void RemoveTemplateCache(this DistributedCache dc, int templateId)
{
dc.Remove(new Guid(DistributedCache.TemplateRefresherId), templateId);
}
}
#endregion
#region Page cache
/// <summary>
/// Refreshes the cache amongst servers for all pages
/// </summary>
@@ -59,7 +64,7 @@ namespace Umbraco.Web.Cache
public static void RefreshPageCache(this DistributedCache dc, int documentId)
{
dc.Refresh(new Guid(DistributedCache.PageCacheRefresherId), documentId);
}
}
/// <summary>
/// Refreshes page cache for all instances passed in
@@ -89,8 +94,10 @@ namespace Umbraco.Web.Cache
public static void RemovePageCache(this DistributedCache dc, int documentId)
{
dc.Remove(new Guid(DistributedCache.PageCacheRefresherId), documentId);
}
}
#endregion
#region Member cache
/// <summary>
/// Refreshes the cache amongst servers for a member
/// </summary>
@@ -109,8 +116,10 @@ namespace Umbraco.Web.Cache
public static void RemoveMemberCache(this DistributedCache dc, int memberId)
{
dc.Remove(new Guid(DistributedCache.MemberCacheRefresherId), memberId);
}
}
#endregion
#region Media Cache
/// <summary>
/// Refreshes the cache amongst servers for a media item
/// </summary>
@@ -149,8 +158,21 @@ namespace Umbraco.Web.Cache
public static void RemoveMediaCache(this DistributedCache dc, params IMedia[] media)
{
dc.Remove(new Guid(DistributedCache.MediaCacheRefresherId), x => x.Id, media);
}
}
#endregion
#region Macro Cache
/// <summary>
/// Clears the cache for all macros on the current server
/// </summary>
/// <param name="dc"></param>
public static void ClearAllMacroCacheOnCurrentServer(this DistributedCache dc)
{
//NOTE: The 'false' ensure that it will only refresh on the current server, not post to all servers
dc.RefreshAll(new Guid(DistributedCache.MacroCacheRefresherId), false);
}
/// <summary>
/// Refreshes the cache amongst servers for a macro item
/// </summary>
@@ -182,7 +204,7 @@ namespace Umbraco.Web.Cache
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
@@ -208,6 +230,39 @@ namespace Umbraco.Web.Cache
{
dc.Remove(new Guid(DistributedCache.MacroCacheRefresherId), macro1 => macro1.Model.Id, macro);
}
}
#endregion
#region Content type cache
/// <summary>
/// Remove all cache for a given content type
/// </summary>
/// <param name="dc"></param>
/// <param name="contentType"></param>
public static void RefreshContentTypeCache(this DistributedCache dc, IContentType contentType)
{
if (contentType != null)
{
//dc.Refresh(new Guid(DistributedCache.ContentTypeCacheRefresherId), x => x.Id, contentType);
dc.RefreshByJson(new Guid(DistributedCache.ContentTypeCacheRefresherId),
ContentTypeCacheRefresher.SerializeToJsonPayload(false, contentType));
}
}
/// <summary>
/// Remove all cache for a given media type
/// </summary>
/// <param name="dc"></param>
/// <param name="mediaType"></param>
public static void RefreshMediaTypeCache(this DistributedCache dc, IMediaType mediaType)
{
if (mediaType != null)
{
//dc.Refresh(new Guid(DistributedCache.ContentTypeCacheRefresherId), x => x.Id, mediaType);
dc.RefreshByJson(new Guid(DistributedCache.ContentTypeCacheRefresherId),
ContentTypeCacheRefresher.SerializeToJsonPayload(false, mediaType));
}
}
/// <summary>
@@ -219,7 +274,9 @@ namespace Umbraco.Web.Cache
{
if (contentType != null)
{
dc.Remove(new Guid(DistributedCache.ContentTypeCacheRefresherId), x => x.Id, contentType);
//dc.Remove(new Guid(DistributedCache.ContentTypeCacheRefresherId), x => x.Id, contentType);
dc.RemoveByJson(new Guid(DistributedCache.ContentTypeCacheRefresherId),
ContentTypeCacheRefresher.SerializeToJsonPayload(true, contentType));
}
}
@@ -232,19 +289,12 @@ namespace Umbraco.Web.Cache
{
if (mediaType != null)
{
dc.Remove(new Guid(DistributedCache.ContentTypeCacheRefresherId), x => x.Id, mediaType);
//dc.Remove(new Guid(DistributedCache.ContentTypeCacheRefresherId), x => x.Id, mediaType);
dc.RemoveByJson(new Guid(DistributedCache.ContentTypeCacheRefresherId),
ContentTypeCacheRefresher.SerializeToJsonPayload(true, mediaType));
}
}
/// <summary>
/// Clears the cache for all macros on the current server
/// </summary>
/// <param name="dc"></param>
public static void ClearAllMacroCacheOnCurrentServer(this DistributedCache dc)
{
//NOTE: The 'false' ensure that it will only refresh on the current server, not post to all servers
dc.RefreshAll(new Guid(DistributedCache.MacroCacheRefresherId), false);
}
}
#endregion
public static void ClearXsltCacheOnCurrentServer(this DistributedCache dc)
{