From 7631522a9e952f86b2c17ed03489058c2c4f6bfa Mon Sep 17 00:00:00 2001 From: sgay Date: Wed, 26 Jan 2011 10:46:47 -0100 Subject: [PATCH] fix #29966 - cache xslt extensions --- umbraco/presentation/macro.cs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/umbraco/presentation/macro.cs b/umbraco/presentation/macro.cs index 73b89e7247..8fa7a7583d 100644 --- a/umbraco/presentation/macro.cs +++ b/umbraco/presentation/macro.cs @@ -761,14 +761,36 @@ namespace umbraco /// Gets a collection of all XSLT extensions for macros, including predefined extensions. /// /// A dictionary of name/extension instance pairs. - public static Dictionary GetXsltExtensions() + public static Dictionary GetXsltExtensions() + { + // zb-00041 #29966 : cache the extensions + + // We could cache the extensions in a static variable but then the cache + // would not be refreshed when the .config file is modified. An application + // restart would be required. Better use the cache and add a dependency. + + return umbraco.cms.businesslogic.cache.Cache.GetCacheItem( + _xsltExtensionsCacheKey, _xsltExtensionsSyncLock, + CacheItemPriority.Normal, // normal priority + null, // no refresh action + new CacheDependency(_xsltExtensionsConfig), // depends on the .config file + TimeSpan.FromDays(1), // expires in 1 day (?) + () => { return GetXsltExtensionsImpl(); }); + } + + // zb-00041 #29966 : cache the extensions + const string _xsltExtensionsCacheKey = "UmbracoXsltExtensions"; + static string _xsltExtensionsConfig = IOHelper.MapPath(SystemDirectories.Config + "/xsltExtensions.config"); + static object _xsltExtensionsSyncLock = new object(); + + static Dictionary GetXsltExtensionsImpl() { // fill a dictionary with the predefined extensions var extensions = new Dictionary(GetPredefinedXsltExtensions()); // Load the XSLT extensions configuration var xsltExt = new XmlDocument(); - xsltExt.Load(IOHelper.MapPath(SystemDirectories.Config + "/xsltExtensions.config")); + xsltExt.Load(_xsltExtensionsConfig); // add all descendants of the XsltExtensions element foreach (XmlNode xsltEx in xsltExt.SelectSingleNode("/XsltExtensions"))