Implemented an extension method to lessen duplication of code
This commit is contained in:
@@ -142,10 +142,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
|
||||
// elements cache (if we don't want to pollute the elements cache with short-lived
|
||||
// data) depending on settings
|
||||
// for members, always cache in the snapshot cache - never pollute elements cache
|
||||
if (!_publishedSnapshotAccessor.TryGetPublishedSnapshot(out publishedSnapshot))
|
||||
{
|
||||
throw new InvalidOperationException("Wasn't possible to a get a valid Snapshot");
|
||||
}
|
||||
publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot();
|
||||
cache = publishedSnapshot == null
|
||||
? null
|
||||
: ((_isPreviewing == false || PublishedSnapshotService.FullCacheWhenPreviewing) && (_isMember == false)
|
||||
@@ -155,10 +152,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
|
||||
break;
|
||||
case PropertyCacheLevel.Snapshot:
|
||||
// cache within the snapshot cache
|
||||
if (!_publishedSnapshotAccessor.TryGetPublishedSnapshot(out publishedSnapshot))
|
||||
{
|
||||
throw new InvalidOperationException("Wasn't possible to a get a valid Snapshot");
|
||||
}
|
||||
publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot();
|
||||
cache = publishedSnapshot?.SnapshotCache;
|
||||
cacheValues = GetCacheValues(cache);
|
||||
break;
|
||||
|
||||
@@ -238,10 +238,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
|
||||
get
|
||||
{
|
||||
var getById = GetGetterById();
|
||||
if (!_publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot))
|
||||
{
|
||||
throw new InvalidOperationException("Wasn't possible to a get a valid Snapshot");
|
||||
}
|
||||
var publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot();
|
||||
return getById(publishedSnapshot, IsPreviewing, ParentId);
|
||||
}
|
||||
}
|
||||
@@ -252,10 +249,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
|
||||
get
|
||||
{
|
||||
var getById = GetGetterById();
|
||||
if (!_publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot))
|
||||
{
|
||||
throw new InvalidOperationException("Wasn't possible to a get a valid Snapshot");
|
||||
}
|
||||
var publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot();
|
||||
var id = _contentNode.FirstChildContentId;
|
||||
|
||||
while (id > 0)
|
||||
@@ -322,10 +316,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
|
||||
// beware what you use that one for - you don't want to cache its result
|
||||
private IAppCache GetAppropriateCache()
|
||||
{
|
||||
if (!_publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot))
|
||||
{
|
||||
throw new InvalidOperationException("Wasn't possible to a get a valid Snapshot");
|
||||
}
|
||||
var publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot();
|
||||
var cache = publishedSnapshot == null
|
||||
? null
|
||||
: ((IsPreviewing == false || PublishedSnapshotService.FullCacheWhenPreviewing) && (ContentType.ItemType != PublishedItemType.Member)
|
||||
@@ -336,10 +327,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
|
||||
|
||||
private IAppCache GetCurrentSnapshotCache()
|
||||
{
|
||||
if (!_publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot))
|
||||
{
|
||||
throw new InvalidOperationException("Wasn't possible to a get a valid Snapshot");
|
||||
}
|
||||
var publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot();
|
||||
return publishedSnapshot?.SnapshotCache;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user