This repository has been archived by the owner on Dec 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from umco/develop
Preparing v1.1.0 release
- Loading branch information
Showing
33 changed files
with
826 additions
and
432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System.Linq; | ||
using Newtonsoft.Json; | ||
using Our.Umbraco.InnerContent.Helpers; | ||
using Umbraco.Core; | ||
using Umbraco.Core.Sync; | ||
using Umbraco.Web.Cache; | ||
|
||
namespace Our.Umbraco.InnerContent | ||
{ | ||
public class Bootstrap : ApplicationEventHandler | ||
{ | ||
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) | ||
{ | ||
DataTypeCacheRefresher.CacheUpdated += (sender, e) => | ||
{ | ||
if (e.MessageType != MessageType.RefreshByJson) | ||
return; | ||
|
||
// NOTE: The properties for the JSON payload are available here: (Currently there isn't a public API to deserialize the payload) | ||
// https://github.com/umbraco/Umbraco-CMS/blob/release-7.4.0/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs#L64-L68 | ||
var payload = JsonConvert.DeserializeAnonymousType((string)e.MessageObject, new[] { new { Id = default(int) } }); | ||
if (payload == null) | ||
return; | ||
|
||
foreach (var item in payload) | ||
{ | ||
applicationContext.ApplicationCache.RuntimeCache.ClearCacheItem(string.Format(InnerContentConstants.PreValuesCacheKey, item.Id)); | ||
} | ||
}; | ||
|
||
ContentTypeCacheRefresher.CacheUpdated += (sender, e) => | ||
{ | ||
if (e.MessageType != MessageType.RefreshByJson) | ||
return; | ||
|
||
// NOTE: The properties for the JSON payload are available here: (Currently there isn't a public API to deserialize the payload) | ||
// https://github.com/umbraco/Umbraco-CMS/blob/release-7.4.0/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs#L93-L109 | ||
var payload = JsonConvert.DeserializeAnonymousType((string)e.MessageObject, new[] { new { Id = default(int), AliasChanged = default(bool) } }); | ||
if (payload == null) | ||
return; | ||
|
||
// Only update if the content-type alias has changed. | ||
var ids = payload.Where(x => x.AliasChanged).Select(x => x.Id).ToArray(); | ||
if (ids.Length == 0) | ||
return; | ||
|
||
var contentTypes = applicationContext.Services.ContentTypeService.GetAllContentTypes(ids); | ||
foreach (var contentType in contentTypes) | ||
{ | ||
ContentTypeCacheHelper.TryRemove(contentType); | ||
ContentTypeCacheHelper.TryAdd(contentType); | ||
} | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
src/Our.Umbraco.InnerContent/Extensions/PreValueCollectionExtensions.cs
This file was deleted.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
src/Our.Umbraco.InnerContent/Helpers/ContentTypeCacheHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using Umbraco.Core.Models; | ||
using Umbraco.Core.Services; | ||
|
||
namespace Our.Umbraco.InnerContent.Helpers | ||
{ | ||
internal static class ContentTypeCacheHelper | ||
{ | ||
private static readonly ConcurrentDictionary<Guid, string> Forward = new ConcurrentDictionary<Guid, string>(); | ||
private static readonly ConcurrentDictionary<string, Guid> Reverse = new ConcurrentDictionary<string, Guid>(); | ||
|
||
public static void ClearAll() | ||
{ | ||
Forward.Clear(); | ||
Reverse.Clear(); | ||
} | ||
|
||
public static void TryAdd(IContentType contentType) | ||
{ | ||
TryAdd(contentType.Key, contentType.Alias); | ||
} | ||
|
||
public static void TryAdd(Guid guid, string alias) | ||
{ | ||
Forward.TryAdd(guid, alias); | ||
Reverse.TryAdd(alias, guid); | ||
} | ||
|
||
public static bool TryGetAlias(Guid key, out string alias, IContentTypeService contentTypeService = null) | ||
{ | ||
if (Forward.TryGetValue(key, out alias)) | ||
return true; | ||
|
||
// The alias isn't cached, we can attempt to get it via the content-type service, using the GUID. | ||
if (contentTypeService != null) | ||
{ | ||
var contentType = contentTypeService.GetContentType(key); | ||
if (contentType != null) | ||
{ | ||
TryAdd(contentType); | ||
alias = contentType.Alias; | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static bool TryGetGuid(string alias, out Guid key, IContentTypeService contentTypeService = null) | ||
{ | ||
if (Reverse.TryGetValue(alias, out key)) | ||
return true; | ||
|
||
// The GUID isn't cached, we can attempt to get it via the content-type service, using the alias. | ||
if (contentTypeService != null) | ||
{ | ||
var contentType = contentTypeService.GetContentType(alias); | ||
if (contentType != null) | ||
{ | ||
TryAdd(contentType); | ||
key = contentType.Key; | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static void TryRemove(IContentType contentType) | ||
{ | ||
if (TryRemove(contentType.Alias) == false) | ||
{ | ||
TryRemove(contentType.Key); | ||
} | ||
} | ||
|
||
public static bool TryRemove(Guid guid) | ||
{ | ||
return Forward.TryRemove(guid, out string alias) | ||
? Reverse.TryRemove(alias, out guid) | ||
: false; | ||
} | ||
|
||
public static bool TryRemove(string alias) | ||
{ | ||
return Reverse.TryRemove(alias, out Guid guid) | ||
? Forward.TryRemove(guid, out alias) | ||
: false; | ||
} | ||
} | ||
} |
Oops, something went wrong.