Files
Umbraco-CMS/src/Umbraco.PublishedCache.NuCache/DomainCache.cs

52 lines
1.7 KiB
C#
Raw Normal View History

2016-05-27 14:26:28 +02:00
using System.Collections.Generic;
using System.Linq;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Core.Routing;
2016-05-27 14:26:28 +02:00
namespace Umbraco.Cms.Infrastructure.PublishedCache
2016-05-27 14:26:28 +02:00
{
/// <summary>
/// Implements <see cref="IDomainCache"/> for NuCache.
/// </summary>
2021-07-06 07:55:05 +02:00
public class DomainCache : IDomainCache
2016-05-27 14:26:28 +02:00
{
private readonly SnapDictionary<int, Domain>.Snapshot _snapshot;
/// <summary>
/// Initializes a new instance of the <see cref="DomainCache"/> class.
/// </summary>
2018-04-26 16:03:08 +02:00
public DomainCache(SnapDictionary<int, Domain>.Snapshot snapshot, string defaultCulture)
2016-05-27 14:26:28 +02:00
{
_snapshot = snapshot;
DefaultCulture = defaultCulture;
2016-05-27 14:26:28 +02:00
}
/// <inheritdoc />
2016-05-27 14:26:28 +02:00
public IEnumerable<Domain> GetAll(bool includeWildcards)
{
var list = _snapshot.GetAll();
if (includeWildcards == false) list = list.Where(x => x.IsWildcard == false);
return list;
}
/// <inheritdoc />
public IEnumerable<Domain> GetAssigned(int documentId, bool includeWildcards = false)
2016-05-27 14:26:28 +02:00
{
// probably this could be optimized with an index
// but then we'd need a custom DomainStore of some sort
var list = _snapshot.GetAll();
list = list.Where(x => x.ContentId == documentId);
2016-05-27 14:26:28 +02:00
if (includeWildcards == false) list = list.Where(x => x.IsWildcard == false);
return list;
}
2018-04-26 16:03:08 +02:00
/// <inheritdoc />
public bool HasAssigned(int documentId, bool includeWildcards = false)
=> documentId > 0 && GetAssigned(documentId, includeWildcards).Any();
/// <inheritdoc />
2018-04-26 16:03:08 +02:00
public string DefaultCulture { get; }
2016-05-27 14:26:28 +02:00
}
}