diff --git a/src/Umbraco.Web/PublishedCache/ContextualPublishedCache.cs b/src/Umbraco.Web/PublishedCache/ContextualPublishedCache.cs index 88e585775f..b965f09c16 100644 --- a/src/Umbraco.Web/PublishedCache/ContextualPublishedCache.cs +++ b/src/Umbraco.Web/PublishedCache/ContextualPublishedCache.cs @@ -14,12 +14,14 @@ namespace Umbraco.Web.PublishedCache internal abstract class ContextualPublishedCache { protected readonly UmbracoContext UmbracoContext; - private readonly IPublishedCache _cache; - protected ContextualPublishedCache(UmbracoContext umbracoContext, IPublishedCache cache) + /// + /// Initializes a new instance of the with a context. + /// + /// The context. + protected ContextualPublishedCache(UmbracoContext umbracoContext) { UmbracoContext = umbracoContext; - _cache = cache; } /// @@ -27,19 +29,13 @@ namespace Umbraco.Web.PublishedCache /// /// The content unique identifier. /// The content, or null. - public virtual IPublishedContent GetById(int contentId) - { - return _cache.GetById(UmbracoContext, contentId); - } + public abstract IPublishedContent GetById(int contentId); /// /// Gets contents at root. /// /// The contents. - public virtual IEnumerable GetAtRoot() - { - return _cache.GetAtRoot(UmbracoContext); - } + public abstract IEnumerable GetAtRoot(); /// /// Gets a content resulting from an XPath query. @@ -52,10 +48,7 @@ namespace Umbraco.Web.PublishedCache /// value which itself is null, then variables are ignored. /// The XPath expression should reference variables as $var. /// - public virtual IPublishedContent GetSingleByXPath(string xpath, params XPathVariable[] vars) - { - return _cache.GetSingleByXPath(UmbracoContext, xpath, vars); - } + public abstract IPublishedContent GetSingleByXPath(string xpath, params XPathVariable[] vars); /// /// Gets contents resulting from an XPath query. @@ -68,27 +61,18 @@ namespace Umbraco.Web.PublishedCache /// value which itself is null, then variables are ignored. /// The XPath expression should reference variables as $var. /// - public virtual IEnumerable GetByXPath(string xpath, params XPathVariable[] vars) - { - return _cache.GetByXPath(UmbracoContext, xpath, vars); - } + public abstract IEnumerable GetByXPath(string xpath, params XPathVariable[] vars); /// /// Gets an XPath navigator that can be used to navigate contents. /// /// The XPath navigator. - public virtual XPathNavigator GetXPathNavigator() - { - return _cache.GetXPathNavigator(UmbracoContext); - } + public abstract XPathNavigator GetXPathNavigator(); /// /// Gets a value indicating whether the underlying non-contextual cache contains published content. /// /// A value indicating whether the underlying non-contextual cache contains published content. - public virtual bool HasContent() - { - return _cache.HasContent(); - } + public abstract bool HasContent(); } } diff --git a/src/Umbraco.Web/PublishedCache/ContextualPublishedCacheOfT.cs b/src/Umbraco.Web/PublishedCache/ContextualPublishedCacheOfT.cs new file mode 100644 index 0000000000..00ad44860d --- /dev/null +++ b/src/Umbraco.Web/PublishedCache/ContextualPublishedCacheOfT.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Xml.XPath; +using Umbraco.Core.Models; +using Umbraco.Core.Xml; + +namespace Umbraco.Web.PublishedCache +{ + /// + /// Provides access to cached contents in a specified context. + /// + /// The type of the underlying published cache. + internal abstract class ContextualPublishedCache : ContextualPublishedCache + where T : IPublishedCache + { + private readonly T _cache; + + /// + /// Initializes a new instance of the with a context and a published cache. + /// + /// The context. + /// The cache. + protected ContextualPublishedCache(UmbracoContext umbracoContext, T cache) + : base(umbracoContext) + { + _cache = cache; + } + + /// + /// Gets the underlying published cache. + /// + public T InnerCache { get { return _cache; } } + + /// + /// Gets a content identified by its unique identifier. + /// + /// The content unique identifier. + /// The content, or null. + public override IPublishedContent GetById(int contentId) + { + return _cache.GetById(UmbracoContext, contentId); + } + + /// + /// Gets contents at root. + /// + /// The contents. + public override IEnumerable GetAtRoot() + { + return _cache.GetAtRoot(UmbracoContext); + } + + /// + /// Gets a content resulting from an XPath query. + /// + /// The XPath query. + /// Optional XPath variables. + /// The content, or null. + /// + /// If is null, or is empty, or contains only one single + /// value which itself is null, then variables are ignored. + /// The XPath expression should reference variables as $var. + /// + public override IPublishedContent GetSingleByXPath(string xpath, params XPathVariable[] vars) + { + return _cache.GetSingleByXPath(UmbracoContext, xpath, vars); + } + + /// + /// Gets contents resulting from an XPath query. + /// + /// The XPath query. + /// Optional XPath variables. + /// The contents. + /// + /// If is null, or is empty, or contains only one single + /// value which itself is null, then variables are ignored. + /// The XPath expression should reference variables as $var. + /// + public override IEnumerable GetByXPath(string xpath, params XPathVariable[] vars) + { + return _cache.GetByXPath(UmbracoContext, xpath, vars); + } + + /// + /// Gets an XPath navigator that can be used to navigate contents. + /// + /// The XPath navigator. + public override XPathNavigator GetXPathNavigator() + { + return _cache.GetXPathNavigator(UmbracoContext); + } + + /// + /// Gets a value indicating whether the underlying non-contextual cache contains published content. + /// + /// A value indicating whether the underlying non-contextual cache contains published content. + public override bool HasContent() + { + return _cache.HasContent(UmbracoContext); + } + } +} diff --git a/src/Umbraco.Web/PublishedCache/ContextualPublishedContentCache.cs b/src/Umbraco.Web/PublishedCache/ContextualPublishedContentCache.cs index bdbd0265b5..728f114cce 100644 --- a/src/Umbraco.Web/PublishedCache/ContextualPublishedContentCache.cs +++ b/src/Umbraco.Web/PublishedCache/ContextualPublishedContentCache.cs @@ -9,10 +9,8 @@ namespace Umbraco.Web.PublishedCache /// /// Provides access to cached documents in a specified context. /// - internal class ContextualPublishedContentCache : ContextualPublishedCache + internal class ContextualPublishedContentCache : ContextualPublishedCache { - private readonly IPublishedContentCache _cache; - /// /// Initializes a new instance of the class with a published content cache and a context. /// @@ -20,15 +18,7 @@ namespace Umbraco.Web.PublishedCache /// A context. public ContextualPublishedContentCache(IPublishedContentCache cache, UmbracoContext umbracoContext) : base(umbracoContext, cache) - { - _cache = cache; - } - - /// - /// Gets the inner IPublishedContentCache. - /// - /// For unit tests. - internal IPublishedContentCache InnerCache { get { return _cache; } } + { } /// /// Gets content identified by a route. @@ -39,7 +29,7 @@ namespace Umbraco.Web.PublishedCache /// A valid route is either a simple path eg /foo/bar/nil or a root node id and a path, eg 123/foo/bar/nil. public IPublishedContent GetByRoute(string route, bool? hideTopLevelNode = null) { - return _cache.GetByRoute(UmbracoContext, route, hideTopLevelNode); + return InnerCache.GetByRoute(UmbracoContext, route, hideTopLevelNode); } /// @@ -49,7 +39,7 @@ namespace Umbraco.Web.PublishedCache /// The route. public string GetRouteById(int contentId) { - return _cache.GetRouteById(UmbracoContext, contentId); + return InnerCache.GetRouteById(UmbracoContext, contentId); } } } diff --git a/src/Umbraco.Web/PublishedCache/ContextualPublishedMediaCache.cs b/src/Umbraco.Web/PublishedCache/ContextualPublishedMediaCache.cs index c98cf5792c..f3621895e4 100644 --- a/src/Umbraco.Web/PublishedCache/ContextualPublishedMediaCache.cs +++ b/src/Umbraco.Web/PublishedCache/ContextualPublishedMediaCache.cs @@ -9,10 +9,8 @@ namespace Umbraco.Web.PublishedCache /// /// Provides access to cached medias in a specified context. /// - internal class ContextualPublishedMediaCache : ContextualPublishedCache + internal class ContextualPublishedMediaCache : ContextualPublishedCache { - private readonly IPublishedMediaCache _cache; - /// /// Initializes a new instance of the class with a published media cache and a context. /// @@ -20,8 +18,6 @@ namespace Umbraco.Web.PublishedCache /// A context. public ContextualPublishedMediaCache(IPublishedMediaCache cache, UmbracoContext umbracoContext) : base(umbracoContext, cache) - { - _cache = cache; - } + { } } } diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index d6b70cd7b7..120b916c8a 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -330,6 +330,7 @@ +