Files
Umbraco-CMS/src/Umbraco.Infrastructure/Suspendable.cs

108 lines
3.4 KiB
C#
Raw Normal View History

using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Cache;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Examine;
2017-09-19 15:51:47 +02:00
using Umbraco.Web.Cache;
using Umbraco.Web.Search;
2017-09-19 15:51:47 +02:00
namespace Umbraco.Web
{
internal static class Suspendable
{
public static class PageCacheRefresher
{
private static bool _tried, _suspended;
public static bool CanRefreshDocumentCacheFromDatabase
{
get
{
// trying a full refresh
if (_suspended == false) return true;
_tried = true; // remember we tried
return false;
}
}
// trying a partial update
// ok if not suspended, or if we haven't done a full already
public static bool CanUpdateDocumentCache => _suspended == false || _tried == false;
public static void SuspendDocumentCache()
{
StaticApplicationLogging.Logger.LogInformation("Suspend document cache.");
2017-09-19 15:51:47 +02:00
_suspended = true;
}
public static void ResumeDocumentCache(CacheRefresherCollection cacheRefresherCollection)
2017-09-19 15:51:47 +02:00
{
_suspended = false;
StaticApplicationLogging.Logger.LogInformation("Resume document cache (reload:{Tried}).", _tried);
2017-09-19 15:51:47 +02:00
if (_tried == false) return;
_tried = false;
var pageRefresher = cacheRefresherCollection[ContentCacheRefresher.UniqueId];
2017-09-19 15:51:47 +02:00
pageRefresher.RefreshAll();
}
}
//This is really needed at all since the only place this is used is in ExamineComponent and that already maintains a flag of whether it suspsended or not
// AHH... but Deploy probably uses this?
2017-09-19 15:51:47 +02:00
public static class ExamineEvents
{
private static bool _tried, _suspended;
public static bool CanIndex
{
get
{
if (_suspended == false) return true;
_tried = true; // remember we tried
return false;
}
}
public static void SuspendIndexers(ILogger logger)
2017-09-19 15:51:47 +02:00
{
2020-09-15 10:06:17 +02:00
logger.LogInformation("Suspend indexers.");
2017-09-19 15:51:47 +02:00
_suspended = true;
}
public static void ResumeIndexers(IndexRebuilder indexRebuilder, ILogger logger, BackgroundIndexRebuilder backgroundIndexRebuilder)
2017-09-19 15:51:47 +02:00
{
_suspended = false;
StaticApplicationLogging.Logger.LogInformation("Resume indexers (rebuild:{Tried}).", _tried);
2017-09-19 15:51:47 +02:00
if (_tried == false) return;
_tried = false;
backgroundIndexRebuilder.RebuildIndexes(false);
2017-09-19 15:51:47 +02:00
}
}
public static class ScheduledPublishing
{
private static bool _suspended;
public static bool CanRun => _suspended == false;
public static void Suspend()
{
StaticApplicationLogging.Logger.LogInformation("Suspend scheduled publishing.");
2017-09-19 15:51:47 +02:00
_suspended = true;
}
public static void Resume()
{
StaticApplicationLogging.Logger.LogInformation("Resume scheduled publishing.");
2017-09-19 15:51:47 +02:00
_suspended = false;
}
}
}
}