Files
Umbraco-CMS/src/Umbraco.Infrastructure/Suspendable.cs
Paul Johnson 3f5f85880e NetCore: MSDI refactor split CoreRuntime & Remove Current (#9356)
* Split Bootstrap code from CoreRuntime

* Make ContentService method signatures match interface
prevents need to hide the concrete class in tests

* Remove Current

Only bit that bugs me is TreeNode for IconFilePath
I get the feeling it's dead code, but can just use a setter in cs or work out path in js if required.

* Fix tests, remember to terminate IRuntime
2020-11-10 09:50:47 +01:00

106 lines
3.4 KiB
C#

using Microsoft.Extensions.Logging;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Examine;
using Umbraco.Web.Cache;
using Umbraco.Web.Search;
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.");
_suspended = true;
}
public static void ResumeDocumentCache(CacheRefresherCollection cacheRefresherCollection)
{
_suspended = false;
StaticApplicationLogging.Logger.LogInformation("Resume document cache (reload:{Tried}).", _tried);
if (_tried == false) return;
_tried = false;
var pageRefresher = cacheRefresherCollection[ContentCacheRefresher.UniqueId];
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?
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)
{
logger.LogInformation("Suspend indexers.");
_suspended = true;
}
public static void ResumeIndexers(IndexRebuilder indexRebuilder, ILogger logger, BackgroundIndexRebuilder backgroundIndexRebuilder)
{
_suspended = false;
StaticApplicationLogging.Logger.LogInformation("Resume indexers (rebuild:{Tried}).", _tried);
if (_tried == false) return;
_tried = false;
backgroundIndexRebuilder.RebuildIndexes(false);
}
}
public static class ScheduledPublishing
{
private static bool _suspended;
public static bool CanRun => _suspended == false;
public static void Suspend()
{
StaticApplicationLogging.Logger.LogInformation("Suspend scheduled publishing.");
_suspended = true;
}
public static void Resume()
{
StaticApplicationLogging.Logger.LogInformation("Resume scheduled publishing.");
_suspended = false;
}
}
}
}