Files
Umbraco-CMS/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentService.cs

127 lines
4.3 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Services.Implement;
namespace Umbraco.Cms.Infrastructure.PublishedCache.Persistence
{
public class NuCacheContentService : RepositoryService, INuCacheContentService
{
private readonly INuCacheContentRepository _repository;
public NuCacheContentService(INuCacheContentRepository repository, IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory)
: base(provider, loggerFactory, eventMessagesFactory)
{
_repository = repository;
}
/// <inheritdoc/>
public IEnumerable<ContentNodeKit> GetAllContentSources()
=> _repository.GetAllContentSources();
/// <inheritdoc/>
public IEnumerable<ContentNodeKit> GetAllMediaSources()
=> _repository.GetAllMediaSources();
/// <inheritdoc/>
public IEnumerable<ContentNodeKit> GetBranchContentSources(int id)
=> _repository.GetBranchContentSources(id);
/// <inheritdoc/>
public IEnumerable<ContentNodeKit> GetBranchMediaSources(int id)
=> _repository.GetBranchMediaSources(id);
/// <inheritdoc/>
public ContentNodeKit GetContentSource(int id)
=> _repository.GetContentSource(id);
/// <inheritdoc/>
public ContentNodeKit GetMediaSource(int id)
=> _repository.GetMediaSource(id);
/// <inheritdoc/>
public IEnumerable<ContentNodeKit> GetTypeContentSources(IEnumerable<int> ids)
=> _repository.GetTypeContentSources(ids);
/// <inheritdoc/>
public IEnumerable<ContentNodeKit> GetTypeMediaSources(IEnumerable<int> ids)
=> _repository.GetTypeContentSources(ids);
/// <inheritdoc/>
public void DeleteContentItem(IContentBase item)
=> _repository.DeleteContentItem(item);
Netcore: Migrate RepositoryBase and ContentTypeServiceBase events (#10141) * Remove ScopeEntityRemove from ContentRepositoryBase and rely on "ing" notifications * Remove old event handler from ContentEventsTests * Remove ScopedVersionRemove from ContentRepositoryBase and rely on service notifications instead * Remove unused ScopedVersionEventArgs from ContentRepositoryBase * Migrate ScopeEntityRefresh to notification pattern Unfortunately it's still published from the repository base * Add simple content type notifications * Publish Notifications instead of events in ContentTypeServiceBase for simple events * Switch OnChanged to use Notifications for ContentTypeServices * Publish notifications instead of raising ScopedRefreshedEntity on ContentTypeServiceBase * Hook up to the new ContentType notifications * Remove DistributedCacheBinderTests There are no longer any events to really test on. * Remove ContentTypeChange EventArgs * Remove ContentService_Copied from DistributedCacheBinder It's no longer used * Cleanup * Cleanup * Removed uncommented code * Fixed issue with unattented installs * Re-add ContentTreeChangeNotification to DistributedCache * Add new notification for ScopedEntityRemove Marked as obsolete/hidden in editor, since this should only be used for nucache for now, and should really be changed in the future * Mark Refresh notifications as obsolete/hidden These should not be used anywhere outside Nucache, and should be changed to tree change at some point. * Raise ScopedEntityRemoveNotification on repos and use in nucache Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-04-20 12:17:11 +02:00
public void DeleteContentItems(IEnumerable<IContentBase> items)
{
foreach (IContentBase item in items)
{
_repository.DeleteContentItem(item);
}
}
/// <inheritdoc/>
public void RefreshContent(IContent content)
=> _repository.RefreshContent(content);
/// <inheritdoc/>
public void RefreshEntity(IContentBase content)
=> _repository.RefreshEntity(content);
/// <inheritdoc/>
public void Rebuild(
int groupSize = 5000,
IReadOnlyCollection<int> contentTypeIds = null,
IReadOnlyCollection<int> mediaTypeIds = null,
IReadOnlyCollection<int> memberTypeIds = null)
{
using (IScope scope = ScopeProvider.CreateScope(repositoryCacheMode: RepositoryCacheMode.Scoped))
{
if (contentTypeIds != null)
{
scope.ReadLock(Constants.Locks.ContentTree);
}
if (mediaTypeIds != null)
{
scope.ReadLock(Constants.Locks.MediaTree);
}
if (memberTypeIds != null)
{
scope.ReadLock(Constants.Locks.MemberTree);
}
_repository.Rebuild(groupSize, contentTypeIds, mediaTypeIds, memberTypeIds);
scope.Complete();
}
}
/// <inheritdoc/>
public bool VerifyContentDbCache()
{
using IScope scope = ScopeProvider.CreateScope(autoComplete: true);
scope.ReadLock(Constants.Locks.ContentTree);
return _repository.VerifyContentDbCache();
}
/// <inheritdoc/>
public bool VerifyMediaDbCache()
{
using IScope scope = ScopeProvider.CreateScope(autoComplete: true);
scope.ReadLock(Constants.Locks.MediaTree);
return _repository.VerifyMediaDbCache();
}
/// <inheritdoc/>
public bool VerifyMemberDbCache()
{
using IScope scope = ScopeProvider.CreateScope(autoComplete: true);
scope.ReadLock(Constants.Locks.MemberTree);
return _repository.VerifyMemberDbCache();
}
}
}