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