From b8489f18268f3912cde759527cfbf6091638aa0b Mon Sep 17 00:00:00 2001 From: Sean Kearney Date: Wed, 6 Aug 2014 16:19:30 -0400 Subject: [PATCH] Hook publish:end:remote to clear delivery node cache. Fixes #12 --- src/Kernel/Data/FallbackValuesProvider.cs | 43 +++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/Kernel/Data/FallbackValuesProvider.cs b/src/Kernel/Data/FallbackValuesProvider.cs index ae3d5d4..763436e 100644 --- a/src/Kernel/Data/FallbackValuesProvider.cs +++ b/src/Kernel/Data/FallbackValuesProvider.cs @@ -15,7 +15,9 @@ using Sitecore.Data.Fields; using Sitecore.Data.Items; using Sitecore.Diagnostics; +using Sitecore.Events; using Sitecore.Globalization; +using Sitecore.Publishing; namespace FieldFallback.Data { @@ -219,7 +221,7 @@ public virtual bool FieldContainsFallbackValue(Field field, Language language) bool hasFallbackValue = (field.Value == fallbackValue); Logger.Debug("{0}", hasFallbackValue); - return hasFallbackValue; + return hasFallbackValue; } finally { @@ -403,7 +405,7 @@ private void EnableSites() /// The database. private void InitializeEventHandlers(Database database) { - Logger.Info("Instatiating event handlers for database: {0}", database.Name); + Logger.Info("Instantiating event handlers for database: {0}", database.Name); Sitecore.Data.Engines.DataEngine dataEngine = database.Engines.DataEngine; // Hook into the Delete/Remove/Saved events to clear caches @@ -425,13 +427,17 @@ private void InitializeEventHandlers(Database database) dataEngine.CopiedItem += DataEngine_CopiedItem; dataEngine.SavingItem += DataEngine_SavingItem; dataEngine.SavedItem += DataEngine_SavedItem; - dataEngine.SavedItemRemote+=DataEngine_SavedItemRemote; + dataEngine.SavedItemRemote += DataEngine_SavedItemRemote; dataEngine.CreatingItem += DataEngine_CreatingItem; dataEngine.CreatedItem += DataEngine_CreatedItem; dataEngine.AddingFromTemplate += DataEngine_AddingFromTemplate; dataEngine.AddedFromTemplate += DataEngine_AddedFromTemplate; dataEngine.AddingVersion += DataEngine_AddingVersion; dataEngine.AddedVersion += DataEngine_AddedVersion; + + // The delivery nodes must subscribe to the end publish event... + // we need to invalidate the cache of published items + Event.Subscribe("publish:end:remote", new System.EventHandler(this.OnPublishEndRemoteHandled)); } private void DataEngine_RemoveVersion(object sender, ExecutedEventArgs e) @@ -520,6 +526,37 @@ private void DataEngine_AddedVersion(object sender, ExecutedEventArgs /// Disabled FieldFallback and logs the message to the Debug output ///