diff --git a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs
index c9c4300c71..4e86392fd7 100644
--- a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs
+++ b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs
@@ -5,6 +5,7 @@ using umbraco.cms.businesslogic;
using umbraco.cms.businesslogic.macro;
using umbraco.cms.businesslogic.member;
using System.Linq;
+using umbraco.cms.businesslogic.template;
namespace Umbraco.Web.Cache
{
@@ -17,9 +18,15 @@ namespace Umbraco.Web.Cache
{
if (UmbracoSettings.UmbracoLibraryCacheDuration <= 0) return;
+ //Bind to template events
+
+ Template.AfterSave += TemplateAfterSave;
+ Template.AfterDelete += TemplateAfterDelete;
+
//Bind to macro events
Macro.AfterSave += MacroAfterSave;
+ Macro.AfterDelete += MacroAfterDelete;
//Bind to member events
@@ -37,6 +44,36 @@ namespace Umbraco.Web.Cache
MediaService.Trashing += MediaServiceTrashing;
}
+ ///
+ /// Removes cache for template
+ ///
+ ///
+ ///
+ static void TemplateAfterDelete(Template sender, DeleteEventArgs e)
+ {
+ DistributedCache.Instance.RemoveTemplateCache(sender.Id);
+ }
+
+ ///
+ /// Refresh cache for template
+ ///
+ ///
+ ///
+ static void TemplateAfterSave(Template sender, SaveEventArgs e)
+ {
+ DistributedCache.Instance.RefreshTemplateCache(sender.Id);
+ }
+
+ ///
+ /// Flush macro from cache
+ ///
+ ///
+ ///
+ static void MacroAfterDelete(Macro sender, DeleteEventArgs e)
+ {
+ DistributedCache.Instance.RemoveMacroCache(sender.Id);
+ }
+
///
/// Flush macro from cache
///
diff --git a/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs b/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs
index 4c1e67ba75..b9be4500e9 100644
--- a/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs
+++ b/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs
@@ -17,6 +17,16 @@ namespace Umbraco.Web.Cache
dc.Refresh(new Guid(DistributedCache.TemplateRefresherId), templateId);
}
+ ///
+ /// Removes the cache amongst servers for a template
+ ///
+ ///
+ ///
+ public static void RemoveTemplateCache(this DistributedCache dc, int templateId)
+ {
+ dc.Remove(new Guid(DistributedCache.TemplateRefresherId), templateId);
+ }
+
///
/// Refreshes the cache amongst servers for all pages
///
@@ -75,5 +85,15 @@ namespace Umbraco.Web.Cache
{
dc.Refresh(new Guid(DistributedCache.MacroCacheRefresherId), macroId);
}
+
+ ///
+ /// Removes the cache amongst servers for a macro item
+ ///
+ ///
+ ///
+ public static void RemoveMacroCache(this DistributedCache dc, int macroId)
+ {
+ dc.Remove(new Guid(DistributedCache.MacroCacheRefresherId), macroId);
+ }
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Cache/TemplateCacheRefresher.cs b/src/Umbraco.Web/Cache/TemplateCacheRefresher.cs
index e6eeeb68ce..99496e3a2f 100644
--- a/src/Umbraco.Web/Cache/TemplateCacheRefresher.cs
+++ b/src/Umbraco.Web/Cache/TemplateCacheRefresher.cs
@@ -7,6 +7,8 @@ namespace Umbraco.Web.Cache
{
public class TemplateCacheRefresher : ICacheRefresher
{
+ private const string TemplateCacheKey = "template";
+
public string Name
{
get
@@ -33,12 +35,18 @@ namespace Umbraco.Web.Cache
public void Refresh(int id)
{
- ApplicationContext.Current.ApplicationCache.ClearCacheForTemplate(id);
+ RemoveFromCache(id);
}
public void Remove(int id)
{
- ApplicationContext.Current.ApplicationCache.ClearCacheForTemplate(id);
+ RemoveFromCache(id);
+ }
+
+ private void RemoveFromCache(int id)
+ {
+ ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(
+ string.Format("{0}{1}", TemplateCacheKey, id));
}
}
diff --git a/src/Umbraco.Web/CacheHelperExtensions.cs b/src/Umbraco.Web/CacheHelperExtensions.cs
index 84aa3012ba..e2bb75716f 100644
--- a/src/Umbraco.Web/CacheHelperExtensions.cs
+++ b/src/Umbraco.Web/CacheHelperExtensions.cs
@@ -46,19 +46,7 @@ namespace Umbraco.Web
}
public const string PartialViewCacheKey = "Umbraco.Web.PartialViewCacheKey";
- private const string TemplateCacheKey = "template";
-
- ///
- /// Clears the cache for a template
- ///
- ///
- ///
- public static void ClearCacheForTemplate(this CacheHelper cacheHelper, int templateId)
- {
- cacheHelper.ClearCacheByKeySearch(
- string.Format("{0}{1}", TemplateCacheKey, templateId));
- }
-
+
///
/// Clears the library cache for media
///
diff --git a/src/Umbraco.Web/WebServices/SaveFileController.cs b/src/Umbraco.Web/WebServices/SaveFileController.cs
index 484a01f1af..3665c3470f 100644
--- a/src/Umbraco.Web/WebServices/SaveFileController.cs
+++ b/src/Umbraco.Web/WebServices/SaveFileController.cs
@@ -109,12 +109,6 @@ namespace Umbraco.Web.WebServices
{
t.Save();
- // Clear cache in rutime
- if (UmbracoSettings.UseDistributedCalls)
- DistributedCache.Instance.RefreshTemplateCache(t.Id);
- else
- ApplicationContext.Current.ApplicationCache.ClearCacheForTemplate(t.Id);
-
return Success(ui.Text("speechBubbles", "templateSavedText"), ui.Text("speechBubbles", "templateSavedHeader"));
}
catch (Exception ex)
diff --git a/src/Umbraco.Web/umbraco.presentation/template.cs b/src/Umbraco.Web/umbraco.presentation/template.cs
index 57c40570b6..45367d290d 100644
--- a/src/Umbraco.Web/umbraco.presentation/template.cs
+++ b/src/Umbraco.Web/umbraco.presentation/template.cs
@@ -11,6 +11,7 @@ using System.Collections;
using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Web;
+using Umbraco.Web.Cache;
using umbraco.DataLayer;
using umbraco.BusinessLogic;
using umbraco.IO;
@@ -561,7 +562,7 @@ namespace umbraco
[Obsolete("Use ApplicationContext.Current.ApplicationCache.ClearCacheForTemplate instead")]
public static void ClearCachedTemplate(int templateID)
{
- ApplicationContext.Current.ApplicationCache.ClearCacheForTemplate(templateID);
+ DistributedCache.Instance.RefreshTemplateCache(templateID);
}
public template(String templateContent)
diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/codeEditorSave.asmx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/codeEditorSave.asmx.cs
index c857b5718a..5d03743666 100644
--- a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/codeEditorSave.asmx.cs
+++ b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/codeEditorSave.asmx.cs
@@ -448,7 +448,7 @@ namespace umbraco.presentation.webservices
return "false";
}
- [Obsolete("This method has been superceded by the REST service /Umbraco/RestServices/SaveFile/SaveTemplate which is powered by the SafeFileController.")]
+ [Obsolete("This method has been superceded by the REST service /Umbraco/RestServices/SaveFile/SaveTemplate which is powered by the SaveFileController.")]
[WebMethod]
public string SaveTemplate(string templateName, string templateAlias, string templateContents, int templateID, int masterTemplateID)
{
@@ -466,13 +466,7 @@ namespace umbraco.presentation.webservices
_template.Save();
- retVal = "true";
-
- // Clear cache in rutime
- if (UmbracoSettings.UseDistributedCalls)
- DistributedCache.Instance.RefreshTemplateCache(_template.Id);
- else
- ApplicationContext.Current.ApplicationCache.ClearCacheForTemplate(_template.Id);
+ retVal = "true";
}
return retVal;
}
diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/legacyAjaxCalls.asmx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/legacyAjaxCalls.asmx.cs
index 48cff6e475..2ffe12e6ec 100644
--- a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/legacyAjaxCalls.asmx.cs
+++ b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/legacyAjaxCalls.asmx.cs
@@ -426,15 +426,10 @@ namespace umbraco.presentation.webservices
tp.MasterTemplate = masterTemplateID;
tp.Design = templateContents;
+ tp.Save();
+
retVal = "true";
- // Clear cache in rutime
- if (UmbracoSettings.UseDistributedCalls)
- DistributedCache.Instance.RefreshTemplateCache(tp.Id);
- else
- ApplicationContext.Current.ApplicationCache.ClearCacheForTemplate(tp.Id);
-
-
return retVal;
}
diff --git a/src/umbraco.webservices/templates/templateService.cs b/src/umbraco.webservices/templates/templateService.cs
index dc632b7361..722a8ca263 100644
--- a/src/umbraco.webservices/templates/templateService.cs
+++ b/src/umbraco.webservices/templates/templateService.cs
@@ -95,7 +95,6 @@ namespace umbraco.webservices.templates
template.Text = carrier.Name;
template.Design = carrier.Design;
template.Save();
- clearCachedTemplate(template);
return template.Id;
}
@@ -120,9 +119,6 @@ namespace umbraco.webservices.templates
template.Text = carrier.Name;
template.Design = carrier.Design;
template.Save();
-
-
- clearCachedTemplate(template);
}
[WebMethod]
@@ -206,14 +202,5 @@ namespace umbraco.webservices.templates
}
}
- private void clearCachedTemplate(cms.businesslogic.template.Template cachedTemplate)
- {
- // Clear cache in rutime
- if (UmbracoSettings.UseDistributedCalls)
- DistributedCache.Instance.RefreshTemplateCache(cachedTemplate.Id);
- else
- ApplicationContext.Current.ApplicationCache.ClearCacheForTemplate(cachedTemplate.Id);
- }
-
}
}
\ No newline at end of file