2020-09-16 13:08:27 +02:00
using Microsoft.Extensions.Logging ;
2021-02-18 11:06:02 +01:00
using Umbraco.Cms.Core ;
using Umbraco.Cms.Core.Cache ;
2020-11-10 08:50:47 +00:00
using Umbraco.Core ;
2020-02-18 13:34:31 +01:00
using Umbraco.Core.Cache ;
2018-03-28 16:12:43 +11:00
using Umbraco.Examine ;
2017-09-19 15:51:47 +02:00
using Umbraco.Web.Cache ;
2018-03-28 16:12:43 +11:00
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 ( )
{
2020-11-10 08:50:47 +00:00
StaticApplicationLogging . Logger . LogInformation ( "Suspend document cache." ) ;
2017-09-19 15:51:47 +02:00
_suspended = true ;
}
2020-02-18 13:34:31 +01:00
public static void ResumeDocumentCache ( CacheRefresherCollection cacheRefresherCollection )
2017-09-19 15:51:47 +02:00
{
_suspended = false ;
2020-11-10 08:50:47 +00:00
StaticApplicationLogging . Logger . LogInformation ( "Resume document cache (reload:{Tried})." , _tried ) ;
2017-09-19 15:51:47 +02:00
if ( _tried = = false ) return ;
_tried = false ;
2020-02-18 13:34:31 +01:00
var pageRefresher = cacheRefresherCollection [ ContentCacheRefresher . UniqueId ] ;
2017-09-19 15:51:47 +02:00
pageRefresher . RefreshAll ( ) ;
}
}
2019-08-02 01:15:08 +10:00
//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 ;
}
}
2018-11-28 01:23:02 +11:00
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 ;
}
2020-02-18 13:34:31 +01:00
public static void ResumeIndexers ( IndexRebuilder indexRebuilder , ILogger logger , BackgroundIndexRebuilder backgroundIndexRebuilder )
2017-09-19 15:51:47 +02:00
{
_suspended = false ;
2020-11-10 08:50:47 +00:00
StaticApplicationLogging . Logger . LogInformation ( "Resume indexers (rebuild:{Tried})." , _tried ) ;
2017-09-19 15:51:47 +02:00
if ( _tried = = false ) return ;
_tried = false ;
2020-02-18 13:34:31 +01:00
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 ( )
{
2020-11-10 08:50:47 +00:00
StaticApplicationLogging . Logger . LogInformation ( "Suspend scheduled publishing." ) ;
2017-09-19 15:51:47 +02:00
_suspended = true ;
}
public static void Resume ( )
{
2020-11-10 08:50:47 +00:00
StaticApplicationLogging . Logger . LogInformation ( "Resume scheduled publishing." ) ;
2017-09-19 15:51:47 +02:00
_suspended = false ;
}
}
}
}