From d904bfff159a3da8ce1c664e2492bf104c1be7ec Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Mon, 3 Feb 2014 01:26:33 +0700 Subject: [PATCH] Added CacheKey (SiteMapCacheKey) as a property of ISiteMap and ISiteMapSettings so it can be used within the SiteMap to build request caching keys. --- .../Unit/Web/Html/FakeSiteMap.cs | 5 +++++ .../Builder/SiteMapBuilderSet.cs | 4 +++- .../MvcSiteMapProvider/ISiteMap.cs | 3 ++- .../MvcSiteMapProvider/ISiteMapSettings.cs | 1 + .../MvcSiteMapProvider/Loader/SiteMapCreator.cs | 5 +++-- .../MvcSiteMapProvider/SiteMap.cs | 16 ++++++++++++++-- 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider.Tests/Unit/Web/Html/FakeSiteMap.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider.Tests/Unit/Web/Html/FakeSiteMap.cs index da8f72c4..a81550c0 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider.Tests/Unit/Web/Html/FakeSiteMap.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider.Tests/Unit/Web/Html/FakeSiteMap.cs @@ -323,6 +323,11 @@ public bool IsAccessibleToUser(ISiteMapNode node) } public string ResourceKey { get; set; } + + public string CacheKey + { + get { throw new NotImplementedException(); } + } public bool SecurityTrimmingEnabled { diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/SiteMapBuilderSet.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/SiteMapBuilderSet.cs index 7fae0b95..8415387a 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/SiteMapBuilderSet.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Builder/SiteMapBuilderSet.cs @@ -67,7 +67,7 @@ ICacheDetails cacheDetails protected readonly ISiteMapBuilder siteMapBuilder; protected readonly ICacheDetails cacheDetails; - #region ISiteMapBuilderSet Members + #region ISiteMapBuilderSet Members public virtual ISiteMapBuilder Builder { @@ -79,6 +79,8 @@ public virtual ICacheDetails CacheDetails get { return this.cacheDetails; } } + public virtual string SiteMapCacheKey { get; set; } + public virtual bool SecurityTrimmingEnabled { get { return this.securityTrimmingEnabled; } diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/ISiteMap.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/ISiteMap.cs index 68635d31..269afbcf 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/ISiteMap.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/ISiteMap.cs @@ -37,7 +37,8 @@ public interface ISiteMap void HintAncestorNodes(ISiteMapNode node, int upLevel); void HintNeighborhoodNodes(ISiteMapNode node, int upLevel, int downLevel); bool IsAccessibleToUser(ISiteMapNode node); - string ResourceKey { get; set; } + string CacheKey { get; } + string ResourceKey { get; set; } // TODO: Remove setter in version 5. bool SecurityTrimmingEnabled { get; } bool UseTitleIfDescriptionNotProvided { get; } bool VisibilityAffectsDescendants { get; } diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/ISiteMapSettings.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/ISiteMapSettings.cs index 67d31062..44144bc8 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/ISiteMapSettings.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/ISiteMapSettings.cs @@ -4,6 +4,7 @@ namespace MvcSiteMapProvider { public interface ISiteMapSettings { + string SiteMapCacheKey { get; set; } bool SecurityTrimmingEnabled { get; } bool EnableLocalization { get; } bool VisibilityAffectsDescendants { get; } diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Loader/SiteMapCreator.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Loader/SiteMapCreator.cs index 88cdb01b..b02ebd51 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Loader/SiteMapCreator.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Loader/SiteMapCreator.cs @@ -43,7 +43,6 @@ public virtual ISiteMap CreateSiteMap(string siteMapCacheKey) var builderSet = this.GetBuilderSet(siteMapCacheKey); var siteMap = siteMapFactory.Create(builderSet.Builder, builderSet); - siteMap.ResourceKey = siteMapCacheKey; siteMap.BuildSiteMap(); return siteMap; @@ -60,7 +59,9 @@ public virtual ICacheDetails GetCacheDetails(string siteMapCacheKey) protected virtual ISiteMapBuilderSet GetBuilderSet(string siteMapCacheKey) { var builderSetName = siteMapCacheKeyToBuilderSetMapper.GetBuilderSetName(siteMapCacheKey); - return siteMapBuilderSetStrategy.GetBuilderSet(builderSetName); + var builderSet = siteMapBuilderSetStrategy.GetBuilderSet(builderSetName); + builderSet.SiteMapCacheKey = siteMapCacheKey; + return builderSet; } } } diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMap.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMap.cs index 5c5528ee..8733a16e 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMap.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMap.cs @@ -574,7 +574,20 @@ public virtual bool IsAccessibleToUser(ISiteMapNode node) /// object, the GetImplicitResourceString method takes precedence over the /// GetExplicitResourceString when the localization is enabled with the EnableLocalization property set to true. /// - public virtual string ResourceKey { get; set; } + public virtual string ResourceKey + { + get { return this.siteMapSettings.SiteMapCacheKey; } + set { /* do nothing */ } + } + + /// + /// Gets a string representing the cache key of the current SiteMap object. This key (which can be though of as the name) can be used + /// to retrieve the SiteMap object. It is also used to build request-cache keys so values can persist in the same request across SiteMap builds. + /// + public virtual string CacheKey + { + get { return this.siteMapSettings.SiteMapCacheKey; } + } /// /// Gets a Boolean value indicating whether a site map provider filters site map nodes based on a user's role. @@ -863,6 +876,5 @@ protected virtual void ThrowIfAreaNameInvalid(ISiteMapNode node) } #endregion - } }