This repository has been archived by the owner on Jun 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced the DataType's cache expiry with the distributed cache refre…
…sher This is the approach to use to support load-balancing
- Loading branch information
1 parent
78b071f
commit fc5086b
Showing
3 changed files
with
33 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,39 @@ | ||
using Umbraco.Core; | ||
using Umbraco.Core.Events; | ||
using Umbraco.Core.Models; | ||
using Umbraco.Core.Services; | ||
using System; | ||
using Newtonsoft.Json; | ||
using Our.Umbraco.NestedContent.Helpers; | ||
using Umbraco.Core; | ||
using Umbraco.Core.Cache; | ||
using Umbraco.Core.Sync; | ||
using Umbraco.Web.Cache; | ||
|
||
namespace Our.Umbraco.NestedContent | ||
{ | ||
public class Bootstrap : ApplicationEventHandler | ||
{ | ||
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) | ||
{ | ||
DataTypeService.Saved += ExpireCache; | ||
CacheRefresherBase<DataTypeCacheRefresher>.CacheUpdated += DataTypeCacheRefresher_Updated; | ||
} | ||
|
||
private void ExpireCache(IDataTypeService sender, SaveEventArgs<IDataTypeDefinition> e) | ||
private void DataTypeCacheRefresher_Updated(DataTypeCacheRefresher sender, CacheRefresherEventArgs e) | ||
{ | ||
foreach (var dataType in e.SavedEntities) | ||
if (e.MessageType == MessageType.RefreshByJson) | ||
{ | ||
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem( | ||
string.Concat("Our.Umbraco.NestedContent.GetPreValuesCollectionByDataTypeId_", dataType.Id)); | ||
var payload = JsonConvert.DeserializeObject<JsonPayload[]>((string)e.MessageObject); | ||
if (payload != null) | ||
{ | ||
foreach (var item in payload) | ||
{ | ||
NestedContentHelper.ClearCache(item.Id); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private class JsonPayload | ||
{ | ||
public Guid UniqueId { get; set; } | ||
public int Id { get; set; } | ||
} | ||
} | ||
} |
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