using Umbraco.Cms.Core.Cache;
namespace Umbraco.Cms.Core.PublishedCache;
///
/// Creates and manages instances.
///
public interface IPublishedSnapshotService : IDisposable
{
/* Various places (such as Node) want to access the XML content, today as an XmlDocument
* but to migrate to a new cache, they're migrating to an XPathNavigator. Still, they need
* to find out how to get that navigator.
*
* Because a cache such as NuCache is contextual i.e. it has a "snapshot" thing and remains
* consistent over the snapshot, the navigator has to come from the "current" snapshot.
*
* So although everything should be injected... we also need a notion of "the current published
* snapshot". This is provided by the IPublishedSnapshotAccessor.
*
*/
///
/// Creates a published snapshot.
///
/// A preview token, or null if not previewing.
/// A published snapshot.
///
/// If is null, the snapshot is not previewing, else it
/// is previewing, and what is or is not visible in preview depends on the content of the token,
/// which is not specified and depends on the actual published snapshot service implementation.
///
IPublishedSnapshot CreatePublishedSnapshot(string? previewToken);
///
/// Rebuilds internal database caches (but does not reload).
///
///
/// If not null will process content for the matching content types, if empty will process all
/// content
///
///
/// If not null will process content for the matching media types, if empty will process all
/// media
///
///
/// If not null will process content for the matching members types, if empty will process all
/// members
///
///
///
/// Forces the snapshot service to rebuild its internal database caches. For instance, some caches
/// may rely on a database table to store pre-serialized version of documents.
///
///
/// This does *not* reload the caches. Caches need to be reloaded, for instance via
/// RefreshAllPublishedSnapshot method.
///
///
void Rebuild(
IReadOnlyCollection? contentTypeIds = null,
IReadOnlyCollection? mediaTypeIds = null,
IReadOnlyCollection? memberTypeIds = null);
///
/// Rebuilds all internal database caches (but does not reload).
///
///
///
/// Forces the snapshot service to rebuild its internal database caches. For instance, some caches
/// may rely on a database table to store pre-serialized version of documents.
///
///
/// This does *not* reload the caches. Caches need to be reloaded, for instance via
/// RefreshAllPublishedSnapshot method.
///
///
void RebuildAll() => Rebuild(Array.Empty(), Array.Empty(), Array.Empty());
/* An IPublishedCachesService implementation can rely on transaction-level events to update
* its internal, database-level data, as these events are purely internal. However, it cannot
* rely on cache refreshers CacheUpdated events to update itself, as these events are external
* and the order-of-execution of the handlers cannot be guaranteed, which means that some
* user code may run before Umbraco is finished updating itself. Instead, the cache refreshers
* explicitly notify the service of changes.
*
*/
///
/// Notifies of content cache refresher changes.
///
/// The changes.
/// A value indicating whether draft contents have been changed in the cache.
/// A value indicating whether published contents have been changed in the cache.
void Notify(ContentCacheRefresher.JsonPayload[] payloads, out bool draftChanged, out bool publishedChanged);
///
/// Notifies of media cache refresher changes.
///
/// The changes.
/// A value indicating whether medias have been changed in the cache.
void Notify(MediaCacheRefresher.JsonPayload[] payloads, out bool anythingChanged);
// there is no NotifyChanges for MemberCacheRefresher because we're not caching members.
///
/// Notifies of content type refresher changes.
///
/// The changes.
void Notify(ContentTypeCacheRefresher.JsonPayload[] payloads);
///
/// Notifies of data type refresher changes.
///
/// The changes.
void Notify(DataTypeCacheRefresher.JsonPayload[] payloads);
///
/// Notifies of domain refresher changes.
///
/// The changes.
void Notify(DomainCacheRefresher.JsonPayload[] payloads);
///
/// Cleans up unused snapshots
///
Task CollectAsync();
}