Fix and cleanup

This commit is contained in:
Stephan
2019-06-07 11:15:58 +02:00
parent 7fd6bfa163
commit 14a056f4f4
24 changed files with 322 additions and 302 deletions

View File

@@ -14,17 +14,15 @@ namespace Umbraco.Web.PublishedCache.NuCache
internal class MediaCache : PublishedCacheBase, IPublishedMediaCache, INavigableData, IDisposable
{
private readonly ContentStore.Snapshot _snapshot;
private readonly IAppCache _snapshotCache;
private readonly IAppCache _elementsCache;
private readonly IVariationContextAccessor _variationContextAccessor;
#region Constructors
public MediaCache(bool previewDefault, ContentStore.Snapshot snapshot, IAppCache snapshotCache, IAppCache elementsCache)
public MediaCache(bool previewDefault, ContentStore.Snapshot snapshot, IVariationContextAccessor variationContextAccessor)
: base(previewDefault)
{
_snapshot = snapshot;
_snapshotCache = snapshotCache;
_elementsCache = elementsCache;
_variationContextAccessor = variationContextAccessor;
}
#endregion
@@ -65,30 +63,16 @@ namespace Umbraco.Web.PublishedCache.NuCache
return n != null;
}
public override IEnumerable<IPublishedContent> GetAtRoot(bool preview)
IEnumerable<IPublishedContent> INavigableData.GetAtRoot(bool preview) => GetAtRoot(preview);
public override IEnumerable<IPublishedContent> GetAtRoot(bool preview, string culture = null)
{
if (PublishedSnapshotService.CacheContentCacheRoots == false)
return GetAtRootNoCache();
// handle context culture for variant
if (culture == null)
culture = _variationContextAccessor?.VariationContext?.Culture ?? "";
var cache = preview == false || PublishedSnapshotService.FullCacheWhenPreviewing
? _elementsCache
: _snapshotCache;
if (cache == null)
return GetAtRootNoCache();
// note: ToArray is important here, we want to cache the result, not the function!
return (IEnumerable<IPublishedContent>)cache.Get(
CacheKeys.MediaCacheRoots(false), // ignore preview, only 1 key!
() => GetAtRootNoCache().ToArray());
}
private IEnumerable<IPublishedContent> GetAtRootNoCache()
{
var c = _snapshot.GetAtRoot();
// ignore preview, there's only draft for media
return c.Select(n => n.PublishedModel);
var atRoot = _snapshot.GetAtRoot().Select(x => x.PublishedModel);
return culture == "*" ? atRoot : atRoot.Where(x => x.IsInvariantOrHasCulture(culture));
}
public override bool HasContent(bool preview)