Published variants - WIP
This commit is contained in:
@@ -89,7 +89,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.Navigable
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
// custom property, ie element
|
||||
return properties[index].XPathValue;
|
||||
return properties[index].GetXPathValue();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
_publishedSnapshotAccessor = origin._publishedSnapshotAccessor;
|
||||
}
|
||||
|
||||
public override bool HasValue => _sourceValue != null
|
||||
public override bool HasValue(int? languageId = null, string segment = null) => _sourceValue != null
|
||||
&& (!(_sourceValue is string) || string.IsNullOrWhiteSpace((string) _sourceValue) == false);
|
||||
|
||||
private class CacheValues
|
||||
@@ -129,39 +129,33 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
return _interValue;
|
||||
}
|
||||
|
||||
public override object SourceValue => _sourceValue;
|
||||
public override object GetSourceValue(int? languageId = null, string segment = null) => _sourceValue;
|
||||
|
||||
public override object Value
|
||||
public override object GetValue(int? languageId = null, string segment = null)
|
||||
{
|
||||
get
|
||||
lock (_locko)
|
||||
{
|
||||
lock (_locko)
|
||||
{
|
||||
var cacheValues = GetCacheValues(PropertyType.CacheLevel);
|
||||
if (cacheValues.ObjectInitialized) return cacheValues.ObjectValue;
|
||||
var cacheValues = GetCacheValues(PropertyType.CacheLevel);
|
||||
if (cacheValues.ObjectInitialized) return cacheValues.ObjectValue;
|
||||
|
||||
// initial reference cache level always is .Content
|
||||
cacheValues.ObjectValue = PropertyType.ConvertInterToObject(_content, PropertyCacheLevel.Element, GetInterValue(), _isPreviewing);
|
||||
cacheValues.ObjectInitialized = true;
|
||||
return cacheValues.ObjectValue;
|
||||
}
|
||||
// initial reference cache level always is .Content
|
||||
cacheValues.ObjectValue = PropertyType.ConvertInterToObject(_content, PropertyCacheLevel.Element, GetInterValue(), _isPreviewing);
|
||||
cacheValues.ObjectInitialized = true;
|
||||
return cacheValues.ObjectValue;
|
||||
}
|
||||
}
|
||||
|
||||
public override object XPathValue
|
||||
public override object GetXPathValue(int? languageId = null, string segment = null)
|
||||
{
|
||||
get
|
||||
lock (_locko)
|
||||
{
|
||||
lock (_locko)
|
||||
{
|
||||
var cacheValues = GetCacheValues(PropertyType.CacheLevel);
|
||||
if (cacheValues.XPathInitialized) return cacheValues.XPathValue;
|
||||
var cacheValues = GetCacheValues(PropertyType.CacheLevel);
|
||||
if (cacheValues.XPathInitialized) return cacheValues.XPathValue;
|
||||
|
||||
// initial reference cache level always is .Content
|
||||
cacheValues.XPathValue = PropertyType.ConvertInterToXPath(_content, PropertyCacheLevel.Element, GetInterValue(), _isPreviewing);
|
||||
cacheValues.XPathInitialized = true;
|
||||
return cacheValues.XPathValue;
|
||||
}
|
||||
// initial reference cache level always is .Content
|
||||
cacheValues.XPathValue = PropertyType.ConvertInterToXPath(_content, PropertyCacheLevel.Element, GetInterValue(), _isPreviewing);
|
||||
cacheValues.XPathInitialized = true;
|
||||
return cacheValues.XPathValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Umbraco.Web.PublishedCache
|
||||
IsMember = propertyType.ContentType.ItemType == PublishedItemType.Member;
|
||||
}
|
||||
|
||||
public override bool HasValue
|
||||
public override bool HasValue(int? languageId = null, string segment = null)
|
||||
=> _sourceValue != null && (!(_sourceValue is string s) || !string.IsNullOrWhiteSpace(s));
|
||||
|
||||
// used to cache the CacheValues of this property
|
||||
@@ -136,39 +136,33 @@ namespace Umbraco.Web.PublishedCache
|
||||
return _interValue;
|
||||
}
|
||||
|
||||
public override object SourceValue => _sourceValue;
|
||||
public override object GetSourceValue(int? languageId = null, string segment = null) => _sourceValue;
|
||||
|
||||
public override object Value
|
||||
public override object GetValue(int? languageId = null, string segment = null)
|
||||
{
|
||||
get
|
||||
{
|
||||
GetCacheLevels(out var cacheLevel, out var referenceCacheLevel);
|
||||
GetCacheLevels(out var cacheLevel, out var referenceCacheLevel);
|
||||
|
||||
lock (_locko)
|
||||
{
|
||||
var cacheValues = GetCacheValues(cacheLevel);
|
||||
if (cacheValues.ObjectInitialized) return cacheValues.ObjectValue;
|
||||
cacheValues.ObjectValue = PropertyType.ConvertInterToObject(Element, referenceCacheLevel, GetInterValue(), IsPreviewing);
|
||||
cacheValues.ObjectInitialized = true;
|
||||
return cacheValues.ObjectValue;
|
||||
}
|
||||
lock (_locko)
|
||||
{
|
||||
var cacheValues = GetCacheValues(cacheLevel);
|
||||
if (cacheValues.ObjectInitialized) return cacheValues.ObjectValue;
|
||||
cacheValues.ObjectValue = PropertyType.ConvertInterToObject(Element, referenceCacheLevel, GetInterValue(), IsPreviewing);
|
||||
cacheValues.ObjectInitialized = true;
|
||||
return cacheValues.ObjectValue;
|
||||
}
|
||||
}
|
||||
|
||||
public override object XPathValue
|
||||
public override object GetXPathValue(int? languageId = null, string segment = null)
|
||||
{
|
||||
get
|
||||
{
|
||||
GetCacheLevels(out var cacheLevel, out var referenceCacheLevel);
|
||||
GetCacheLevels(out var cacheLevel, out var referenceCacheLevel);
|
||||
|
||||
lock (_locko)
|
||||
{
|
||||
var cacheValues = GetCacheValues(cacheLevel);
|
||||
if (cacheValues.XPathInitialized) return cacheValues.XPathValue;
|
||||
cacheValues.XPathValue = PropertyType.ConvertInterToXPath(Element, referenceCacheLevel, GetInterValue(), IsPreviewing);
|
||||
cacheValues.XPathInitialized = true;
|
||||
return cacheValues.XPathValue;
|
||||
}
|
||||
lock (_locko)
|
||||
{
|
||||
var cacheValues = GetCacheValues(cacheLevel);
|
||||
if (cacheValues.XPathInitialized) return cacheValues.XPathValue;
|
||||
cacheValues.XPathValue = PropertyType.ConvertInterToXPath(Element, referenceCacheLevel, GetInterValue(), IsPreviewing);
|
||||
cacheValues.XPathInitialized = true;
|
||||
return cacheValues.XPathValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,31 +27,28 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
/// <summary>
|
||||
/// Gets the raw value of the property.
|
||||
/// </summary>
|
||||
public override object SourceValue => _sourceValue;
|
||||
public override object GetSourceValue(int? languageId = null, string segment = null) => _sourceValue;
|
||||
|
||||
// in the Xml cache, everything is a string, and to have a value
|
||||
// you want to have a non-null, non-empty string.
|
||||
public override bool HasValue => _sourceValue.Trim().Length > 0;
|
||||
public override bool HasValue(int? languageId = null, string segment = null) => _sourceValue.Trim().Length > 0;
|
||||
|
||||
public override object Value
|
||||
public override object GetValue(int? languageId = null, string segment = null)
|
||||
{
|
||||
get
|
||||
{
|
||||
// NOT caching the source (intermediate) value since we'll never need it
|
||||
// everything in Xml cache is per-request anyways
|
||||
// also, properties should not be shared between requests and therefore
|
||||
// are single threaded, so the following code should be safe & fast
|
||||
// NOT caching the source (intermediate) value since we'll never need it
|
||||
// everything in Xml cache is per-request anyways
|
||||
// also, properties should not be shared between requests and therefore
|
||||
// are single threaded, so the following code should be safe & fast
|
||||
|
||||
if (_objectValueComputed) return _objectValue;
|
||||
var inter = PropertyType.ConvertSourceToInter(_content, _sourceValue, _isPreviewing);
|
||||
// initial reference cache level always is .Content
|
||||
_objectValue = PropertyType.ConvertInterToObject(_content, PropertyCacheLevel.Element, inter, _isPreviewing);
|
||||
_objectValueComputed = true;
|
||||
return _objectValue;
|
||||
}
|
||||
if (_objectValueComputed) return _objectValue;
|
||||
var inter = PropertyType.ConvertSourceToInter(_content, _sourceValue, _isPreviewing);
|
||||
// initial reference cache level always is .Content
|
||||
_objectValue = PropertyType.ConvertInterToObject(_content, PropertyCacheLevel.Element, inter, _isPreviewing);
|
||||
_objectValueComputed = true;
|
||||
return _objectValue;
|
||||
}
|
||||
|
||||
public override object XPathValue { get { throw new NotImplementedException(); } }
|
||||
public override object GetXPathValue(int? languageId = null, string segment = null) { throw new NotImplementedException(); }
|
||||
|
||||
public XmlPublishedProperty(PublishedPropertyType propertyType, IPublishedContent content, bool isPreviewing, XmlNode propertyXmlData)
|
||||
: this(propertyType, content, isPreviewing)
|
||||
|
||||
Reference in New Issue
Block a user