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);
}
}
}