Changes all instances of the legacy Cache class to be using ApplicationContext.Current.ApplicationCache.
Fixes: #U4-2039 - ensures macro xslt cache is invalidated in LB scenarios.
This commit is contained in:
@@ -10,6 +10,7 @@ namespace Umbraco.Core.Cache
|
||||
|
||||
public const string MediaCacheKey = "UL_GetMedia";
|
||||
|
||||
public const string MacroXsltCacheKey = "macroXslt_";
|
||||
public const string MacroCacheKey = "UmbracoMacroCache";
|
||||
public const string MacroHtmlCacheKey = "macroHtml_";
|
||||
public const string MacroControlCacheKey = "macroControl_";
|
||||
|
||||
@@ -22,13 +22,13 @@ namespace Umbraco.Core.Cache
|
||||
public abstract IEnumerable<T> GetCacheItemsByKeySearch<T>(string keyStartsWith);
|
||||
public abstract T GetCacheItem<T>(string cacheKey);
|
||||
public abstract T GetCacheItem<T>(string cacheKey, Func<T> getCacheItem);
|
||||
public abstract T GetCacheItem<T>(string cacheKey, TimeSpan timeout, Func<T> getCacheItem);
|
||||
public abstract T GetCacheItem<T>(string cacheKey, CacheItemRemovedCallback refreshAction, TimeSpan timeout, Func<T> getCacheItem);
|
||||
public abstract T GetCacheItem<T>(string cacheKey, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, TimeSpan timeout, Func<T> getCacheItem);
|
||||
public abstract T GetCacheItem<T>(string cacheKey, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency, TimeSpan timeout, Func<T> getCacheItem);
|
||||
public abstract T GetCacheItem<T>(string cacheKey, TimeSpan? timeout, Func<T> getCacheItem);
|
||||
public abstract T GetCacheItem<T>(string cacheKey, CacheItemRemovedCallback refreshAction, TimeSpan? timeout, Func<T> getCacheItem);
|
||||
public abstract T GetCacheItem<T>(string cacheKey, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, TimeSpan? timeout, Func<T> getCacheItem);
|
||||
public abstract T GetCacheItem<T>(string cacheKey, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency, TimeSpan? timeout, Func<T> getCacheItem);
|
||||
public abstract void InsertCacheItem<T>(string cacheKey, CacheItemPriority priority, Func<T> getCacheItem);
|
||||
public abstract void InsertCacheItem<T>(string cacheKey, CacheItemPriority priority, TimeSpan timeout, Func<T> getCacheItem);
|
||||
public abstract void InsertCacheItem<T>(string cacheKey, CacheItemPriority priority, CacheDependency cacheDependency, TimeSpan timeout, Func<T> getCacheItem);
|
||||
public abstract void InsertCacheItem<T>(string cacheKey, CacheItemPriority priority, TimeSpan? timeout, Func<T> getCacheItem);
|
||||
public abstract void InsertCacheItem<T>(string cacheKey, CacheItemPriority priority, CacheDependency cacheDependency, TimeSpan? timeout, Func<T> getCacheItem);
|
||||
public abstract void InsertCacheItem<T>(string cacheKey, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency, TimeSpan? timeout, Func<T> getCacheItem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ namespace Umbraco.Core.Cache
|
||||
/// <param name="getCacheItem"></param>
|
||||
/// <returns></returns>
|
||||
public override TT GetCacheItem<TT>(string cacheKey,
|
||||
TimeSpan timeout, Func<TT> getCacheItem)
|
||||
TimeSpan? timeout, Func<TT> getCacheItem)
|
||||
{
|
||||
return GetCacheItem(cacheKey, null, timeout, getCacheItem);
|
||||
}
|
||||
@@ -195,7 +195,7 @@ namespace Umbraco.Core.Cache
|
||||
/// <param name="getCacheItem"></param>
|
||||
/// <returns></returns>
|
||||
public override TT GetCacheItem<TT>(string cacheKey,
|
||||
CacheItemRemovedCallback refreshAction, TimeSpan timeout,
|
||||
CacheItemRemovedCallback refreshAction, TimeSpan? timeout,
|
||||
Func<TT> getCacheItem)
|
||||
{
|
||||
return GetCacheItem(cacheKey, CacheItemPriority.Normal, refreshAction, timeout, getCacheItem);
|
||||
@@ -212,7 +212,7 @@ namespace Umbraco.Core.Cache
|
||||
/// <param name="getCacheItem"></param>
|
||||
/// <returns></returns>
|
||||
public override TT GetCacheItem<TT>(string cacheKey,
|
||||
CacheItemPriority priority, CacheItemRemovedCallback refreshAction, TimeSpan timeout,
|
||||
CacheItemPriority priority, CacheItemRemovedCallback refreshAction, TimeSpan? timeout,
|
||||
Func<TT> getCacheItem)
|
||||
{
|
||||
return GetCacheItem(cacheKey, priority, refreshAction, null, timeout, getCacheItem);
|
||||
@@ -233,7 +233,7 @@ namespace Umbraco.Core.Cache
|
||||
CacheItemPriority priority,
|
||||
CacheItemRemovedCallback refreshAction,
|
||||
CacheDependency cacheDependency,
|
||||
TimeSpan timeout,
|
||||
TimeSpan? timeout,
|
||||
Func<TT> getCacheItem)
|
||||
{
|
||||
return GetCacheItem(cacheKey, priority, refreshAction, cacheDependency, timeout, getCacheItem, Locker);
|
||||
@@ -301,7 +301,7 @@ namespace Umbraco.Core.Cache
|
||||
/// <param name="getCacheItem"></param>
|
||||
public override void InsertCacheItem<T>(string cacheKey,
|
||||
CacheItemPriority priority,
|
||||
TimeSpan timeout,
|
||||
TimeSpan? timeout,
|
||||
Func<T> getCacheItem)
|
||||
{
|
||||
InsertCacheItem(cacheKey, priority, null, null, timeout, getCacheItem);
|
||||
@@ -319,7 +319,7 @@ namespace Umbraco.Core.Cache
|
||||
public override void InsertCacheItem<T>(string cacheKey,
|
||||
CacheItemPriority priority,
|
||||
CacheDependency cacheDependency,
|
||||
TimeSpan timeout,
|
||||
TimeSpan? timeout,
|
||||
Func<T> getCacheItem)
|
||||
{
|
||||
InsertCacheItem(cacheKey, priority, null, cacheDependency, timeout, getCacheItem);
|
||||
|
||||
@@ -46,22 +46,22 @@ namespace Umbraco.Core.Cache
|
||||
return getCacheItem();
|
||||
}
|
||||
|
||||
public override T GetCacheItem<T>(string cacheKey, TimeSpan timeout, Func<T> getCacheItem)
|
||||
public override T GetCacheItem<T>(string cacheKey, TimeSpan? timeout, Func<T> getCacheItem)
|
||||
{
|
||||
return getCacheItem();
|
||||
}
|
||||
|
||||
public override T GetCacheItem<T>(string cacheKey, CacheItemRemovedCallback refreshAction, TimeSpan timeout, Func<T> getCacheItem)
|
||||
public override T GetCacheItem<T>(string cacheKey, CacheItemRemovedCallback refreshAction, TimeSpan? timeout, Func<T> getCacheItem)
|
||||
{
|
||||
return getCacheItem();
|
||||
}
|
||||
|
||||
public override T GetCacheItem<T>(string cacheKey, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, TimeSpan timeout, Func<T> getCacheItem)
|
||||
public override T GetCacheItem<T>(string cacheKey, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, TimeSpan? timeout, Func<T> getCacheItem)
|
||||
{
|
||||
return getCacheItem();
|
||||
}
|
||||
|
||||
public override T GetCacheItem<T>(string cacheKey, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency, TimeSpan timeout, Func<T> getCacheItem)
|
||||
public override T GetCacheItem<T>(string cacheKey, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency, TimeSpan? timeout, Func<T> getCacheItem)
|
||||
{
|
||||
return getCacheItem();
|
||||
}
|
||||
@@ -70,11 +70,11 @@ namespace Umbraco.Core.Cache
|
||||
{
|
||||
}
|
||||
|
||||
public override void InsertCacheItem<T>(string cacheKey, CacheItemPriority priority, TimeSpan timeout, Func<T> getCacheItem)
|
||||
public override void InsertCacheItem<T>(string cacheKey, CacheItemPriority priority, TimeSpan? timeout, Func<T> getCacheItem)
|
||||
{
|
||||
}
|
||||
|
||||
public override void InsertCacheItem<T>(string cacheKey, CacheItemPriority priority, CacheDependency cacheDependency, TimeSpan timeout, Func<T> getCacheItem)
|
||||
public override void InsertCacheItem<T>(string cacheKey, CacheItemPriority priority, CacheDependency cacheDependency, TimeSpan? timeout, Func<T> getCacheItem)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -273,6 +273,30 @@ namespace Umbraco.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets (and adds if necessary) an item from the cache
|
||||
/// </summary>
|
||||
/// <typeparam name="TT"></typeparam>
|
||||
/// <param name="cacheKey"></param>
|
||||
/// <param name="priority"></param>
|
||||
/// <param name="cacheDependency"></param>
|
||||
/// <param name="getCacheItem"></param>
|
||||
/// <returns></returns>
|
||||
public TT GetCacheItem<TT>(string cacheKey,
|
||||
CacheItemPriority priority,
|
||||
CacheDependency cacheDependency,
|
||||
Func<TT> getCacheItem)
|
||||
{
|
||||
if (!_enableCache)
|
||||
{
|
||||
return _nullCache.GetCacheItem<TT>(cacheKey, priority, null, cacheDependency, null, getCacheItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
return _httpCache.GetCacheItem<TT>(cacheKey, priority, null, cacheDependency, null, getCacheItem);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts an item into the cache, if it already exists in the cache it will be replaced
|
||||
/// </summary>
|
||||
|
||||
@@ -27,7 +27,8 @@ namespace Umbraco.Web.Cache
|
||||
CacheKeys.MacroControlCacheKey,
|
||||
CacheKeys.MacroHtmlCacheKey,
|
||||
CacheKeys.MacroHtmlDateAddedCacheKey,
|
||||
CacheKeys.MacroControlDateAddedCacheKey
|
||||
CacheKeys.MacroControlDateAddedCacheKey,
|
||||
CacheKeys.MacroXsltCacheKey,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -162,15 +162,13 @@ namespace umbraco
|
||||
|
||||
#endregion
|
||||
|
||||
private const string _xsltExtensionsCacheKey = "UmbracoXsltExtensions";
|
||||
private const string XsltExtensionsCacheKey = "UmbracoXsltExtensions";
|
||||
|
||||
private static readonly string _xsltExtensionsConfig =
|
||||
private static readonly string XsltExtensionsConfig =
|
||||
IOHelper.MapPath(SystemDirectories.Config + "/xsltExtensions.config");
|
||||
|
||||
private static readonly object _xsltExtensionsSyncLock = new object();
|
||||
|
||||
private static readonly Func<CacheDependency> _xsltExtensionsDependency =
|
||||
() => new CacheDependency(_xsltExtensionsConfig);
|
||||
() => new CacheDependency(XsltExtensionsConfig);
|
||||
|
||||
/// <summary>
|
||||
/// Creates an empty macro object.
|
||||
@@ -693,22 +691,18 @@ namespace umbraco
|
||||
|
||||
public static XslCompiledTransform getXslt(string XsltFile)
|
||||
{
|
||||
if (HttpRuntime.Cache["macroXslt_" + XsltFile] != null)
|
||||
{
|
||||
return (XslCompiledTransform)HttpRuntime.Cache["macroXslt_" + XsltFile];
|
||||
}
|
||||
else
|
||||
{
|
||||
var xslReader =
|
||||
new XmlTextReader(IOHelper.MapPath(SystemDirectories.Xslt + "/" + XsltFile));
|
||||
|
||||
XslCompiledTransform macroXSLT = CreateXsltTransform(xslReader, GlobalSettings.DebugMode);
|
||||
HttpRuntime.Cache.Insert(
|
||||
"macroXslt_" + XsltFile,
|
||||
macroXSLT,
|
||||
new CacheDependency(IOHelper.MapPath(SystemDirectories.Xslt + "/" + XsltFile)));
|
||||
return macroXSLT;
|
||||
}
|
||||
//TODO: SD: Do we really need to cache this??
|
||||
return ApplicationContext.Current.ApplicationCache.GetCacheItem(
|
||||
CacheKeys.MacroXsltCacheKey + XsltFile,
|
||||
CacheItemPriority.Default,
|
||||
new CacheDependency(IOHelper.MapPath(SystemDirectories.Xslt + "/" + XsltFile)),
|
||||
() =>
|
||||
{
|
||||
using (var xslReader = new XmlTextReader(IOHelper.MapPath(SystemDirectories.Xslt.EnsureEndsWith('/') + XsltFile)))
|
||||
{
|
||||
return CreateXsltTransform(xslReader, GlobalSettings.DebugMode);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void UpdateMacroModel(Hashtable attributes)
|
||||
@@ -737,9 +731,11 @@ namespace umbraco
|
||||
|
||||
public static XslCompiledTransform CreateXsltTransform(XmlTextReader xslReader, bool debugMode)
|
||||
{
|
||||
var macroXSLT = new XslCompiledTransform(debugMode);
|
||||
var xslResolver = new XmlUrlResolver();
|
||||
xslResolver.Credentials = CredentialCache.DefaultCredentials;
|
||||
var macroXslt = new XslCompiledTransform(debugMode);
|
||||
var xslResolver = new XmlUrlResolver
|
||||
{
|
||||
Credentials = CredentialCache.DefaultCredentials
|
||||
};
|
||||
|
||||
xslReader.EntityHandling = EntityHandling.ExpandEntities;
|
||||
|
||||
@@ -747,11 +743,11 @@ namespace umbraco
|
||||
{
|
||||
if (GlobalSettings.ApplicationTrustLevel > AspNetHostingPermissionLevel.Medium)
|
||||
{
|
||||
macroXSLT.Load(xslReader, XsltSettings.TrustedXslt, xslResolver);
|
||||
macroXslt.Load(xslReader, XsltSettings.TrustedXslt, xslResolver);
|
||||
}
|
||||
else
|
||||
{
|
||||
macroXSLT.Load(xslReader, XsltSettings.Default, xslResolver);
|
||||
macroXslt.Load(xslReader, XsltSettings.Default, xslResolver);
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -759,13 +755,13 @@ namespace umbraco
|
||||
xslReader.Close();
|
||||
}
|
||||
|
||||
return macroXSLT;
|
||||
return macroXslt;
|
||||
}
|
||||
|
||||
[Obsolete("This is no longer used in the codebase and will be removed in future versions")]
|
||||
public static void unloadXslt(string XsltFile)
|
||||
{
|
||||
if (HttpRuntime.Cache["macroXslt_" + XsltFile] != null)
|
||||
HttpRuntime.Cache.Remove("macroXslt_" + XsltFile);
|
||||
ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(CacheKeys.MacroXsltCacheKey + XsltFile);
|
||||
}
|
||||
|
||||
#region LoadMacroXslt
|
||||
@@ -1016,7 +1012,7 @@ namespace umbraco
|
||||
// Having this stuff in cache just adds to the gigantic amount of cache data and will cause more cache turnover to happen.
|
||||
|
||||
return ApplicationContext.Current.ApplicationCache.GetCacheItem(
|
||||
_xsltExtensionsCacheKey,
|
||||
XsltExtensionsCacheKey,
|
||||
CacheItemPriority.NotRemovable, // NH 4.7.1, Changing to NotRemovable
|
||||
null, // no refresh action
|
||||
_xsltExtensionsDependency(), // depends on the .config file
|
||||
@@ -1031,7 +1027,7 @@ namespace umbraco
|
||||
|
||||
// Load the XSLT extensions configuration
|
||||
var xsltExt = new XmlDocument();
|
||||
xsltExt.Load(_xsltExtensionsConfig);
|
||||
xsltExt.Load(XsltExtensionsConfig);
|
||||
|
||||
// add all descendants of the XsltExtensions element
|
||||
foreach (XmlNode xsltEx in xsltExt.SelectSingleNode("/XsltExtensions"))
|
||||
|
||||
@@ -17,9 +17,9 @@ namespace umbraco.cms.presentation
|
||||
{
|
||||
// Cache removal checks
|
||||
if (Request.QueryString["clearByType"] != null)
|
||||
cms.businesslogic.cache.Cache.ClearCacheObjectTypes(Request.QueryString["clearByType"]);
|
||||
ApplicationContext.ApplicationCache.ClearCacheObjectTypes(Request.QueryString["clearByType"]);
|
||||
else if (Request.QueryString["clearByKey"] != null)
|
||||
cms.businesslogic.cache.Cache.ClearCacheItem(Request.QueryString["clearByKey"]);
|
||||
ApplicationContext.ApplicationCache.ClearCacheItem(Request.QueryString["clearByKey"]);
|
||||
|
||||
// Put user code to initialize the page here
|
||||
Hashtable ht = cms.businesslogic.cache.Cache.ReturnCacheItemsOrdred();
|
||||
@@ -33,7 +33,7 @@ namespace umbraco.cms.presentation
|
||||
}
|
||||
protected void Button1_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
cms.businesslogic.cache.Cache.ClearAllCache();
|
||||
ApplicationContext.ApplicationCache.ClearAllCache();
|
||||
}
|
||||
|
||||
protected System.Web.UI.HtmlControls.HtmlForm Form1;
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace umbraco.presentation.webservices
|
||||
|
||||
|
||||
// Load balancing - then refresh entire cache
|
||||
// NOTE: This seems a bit excessive to do simply for sorting! I'm going to leave this here for now but
|
||||
// NOTE: SD: This seems a bit excessive to do simply for sorting! I'm going to leave this here for now but
|
||||
// the sort order should be updated in distributed calls when an item is Published (and it most likely is)
|
||||
// but I guess this was put here for a reason at some point.
|
||||
if (UmbracoSettings.UseDistributedCalls)
|
||||
|
||||
Reference in New Issue
Block a user