@@ -206,7 +206,6 @@ private bool CheckXmlContentPopulation()
206
206
FireAfterRefreshContent ( new RefreshContentEventArgs ( ) ) ;
207
207
208
208
// Only save new XML cache to disk if we just repopulated it
209
- // TODO: Re-architect this so that a call to this method doesn't invoke a new thread for saving disk cache
210
209
if ( ! UmbracoSettings . isXmlContentCacheDisabled && ! IsValidDiskCachePresent ( ) )
211
210
{
212
211
QueueXmlForPersistence ( ) ;
@@ -215,7 +214,9 @@ private bool CheckXmlContentPopulation()
215
214
}
216
215
}
217
216
}
218
- Trace . WriteLine ( "Content initialized (was already in context)" ) ;
217
+
218
+ LogHelper . Debug < content > ( ( ) => "Content initialized (was already in context)" ) ;
219
+
219
220
return false ;
220
221
}
221
222
@@ -288,32 +289,33 @@ public delegate void ContentCacheDatabaseLoadXmlStringEventHandler(
288
289
289
290
#endregion
290
291
292
+ [ Obsolete ( "This is no longer used and will be removed in future versions, if you use this method it will not refresh 'async' it will perform the refresh on the current thread which is how it should be doing it" ) ]
293
+ public virtual void RefreshContentFromDatabaseAsync ( )
294
+ {
295
+ RefreshContentFromDatabase ( ) ;
296
+ }
297
+
291
298
/// <summary>
292
- /// Load content from database in a background thread
293
- /// Replaces active content when done.
299
+ /// Load content from database and replaces active content when done.
294
300
/// </summary>
295
- public virtual void RefreshContentFromDatabaseAsync ( )
301
+ public virtual void RefreshContentFromDatabase ( )
296
302
{
297
303
var e = new RefreshContentEventArgs ( ) ;
298
304
FireBeforeRefreshContent ( e ) ;
299
305
300
306
if ( ! e . Cancel )
301
307
{
302
- ThreadPool . QueueUserWorkItem (
303
- delegate
304
- {
305
- XmlDocument xmlDoc = LoadContentFromDatabase ( ) ;
306
- XmlContentInternal = xmlDoc ;
308
+ XmlDocument xmlDoc = LoadContentFromDatabase ( ) ;
309
+ XmlContentInternal = xmlDoc ;
307
310
308
- // It is correct to manually call PersistXmlToFile here event though the setter of XmlContentInternal
309
- // queues this up, because this delegate is executing on a different thread and may complete
310
- // after the request which invoked it (which would normally persist the file on completion)
311
- // So we are responsible for ensuring the content is persisted in this case.
311
+ // It is correct to manually call PersistXmlToFile here event though the setter of XmlContentInternal
312
+ // queues this up, because this delegate is executing on a different thread and may complete
313
+ // after the request which invoked it (which would normally persist the file on completion)
314
+ // So we are responsible for ensuring the content is persisted in this case.
312
315
if ( ! UmbracoSettings . isXmlContentCacheDisabled && UmbracoSettings . continouslyUpdateXmlDiskCache )
313
- PersistXmlToFile ( xmlDoc ) ;
314
- } ) ;
315
-
316
- FireAfterRefreshContent ( e ) ;
316
+ {
317
+ PersistXmlToFile ( xmlDoc ) ;
318
+ }
317
319
}
318
320
}
319
321
@@ -551,33 +553,15 @@ public virtual void UpdateDocumentCache(List<Document> Documents)
551
553
}
552
554
}
553
555
554
- /// <summary>
555
- /// Updates the document cache async.
556
- /// </summary>
557
- /// <param name="documentId">The document id.</param>
558
556
[ Obsolete ( "Method obsolete in version 4.1 and later, please use UpdateDocumentCache" , true ) ]
559
557
public virtual void UpdateDocumentCacheAsync ( int documentId )
560
558
{
561
- //SD: WE've obsoleted this but then didn't make it call the method it should! So we've just
562
- // left a bug behind...???? ARGH.
563
- //.... changed now.
564
- //ThreadPool.QueueUserWorkItem(delegate { UpdateDocumentCache(documentId); });
565
-
566
559
UpdateDocumentCache ( documentId ) ;
567
560
}
568
-
569
- /// <summary>
570
- /// Clears the document cache async.
571
- /// </summary>
572
- /// <param name="documentId">The document id.</param>
561
+
573
562
[ Obsolete ( "Method obsolete in version 4.1 and later, please use ClearDocumentCache" , true ) ]
574
563
public virtual void ClearDocumentCacheAsync ( int documentId )
575
564
{
576
- //SD: WE've obsoleted this but then didn't make it call the method it should! So we've just
577
- // left a bug behind...???? ARGH.
578
- //.... changed now.
579
- //ThreadPool.QueueUserWorkItem(delegate { ClearDocumentCache(documentId); });
580
-
581
565
ClearDocumentCache ( documentId ) ;
582
566
}
583
567
@@ -652,69 +636,6 @@ public virtual void UnPublishNode(int documentId)
652
636
ClearDocumentCache ( documentId ) ;
653
637
}
654
638
655
- ///// <summary>
656
- ///// Uns the publish node async.
657
- ///// </summary>
658
- ///// <param name="documentId">The document id.</param>
659
- //[Obsolete("Please use: umbraco.content.ClearDocumentCacheAsync", true)]
660
- //public virtual void UnPublishNodeAsync(int documentId)
661
- //{
662
-
663
- // ThreadPool.QueueUserWorkItem(delegate { ClearDocumentCache(documentId); });
664
- //}
665
-
666
-
667
- ///// <summary>
668
- ///// Legacy method - you should use the overloaded publishnode(document d) method whenever possible
669
- ///// </summary>
670
- ///// <param name="documentId"></param>
671
- //[Obsolete("Please use: umbraco.content.UpdateDocumentCache", true)]
672
- //public virtual void PublishNode(int documentId)
673
- //{
674
-
675
- // // Get the document
676
- // var d = new Document(documentId);
677
- // PublishNode(d);
678
- //}
679
-
680
-
681
- ///// <summary>
682
- ///// Publishes the node async.
683
- ///// </summary>
684
- ///// <param name="documentId">The document id.</param>
685
- //[Obsolete("Please use: umbraco.content.UpdateDocumentCacheAsync", true)]
686
- //public virtual void PublishNodeAsync(int documentId)
687
- //{
688
-
689
- // UpdateDocumentCacheAsync(documentId);
690
- //}
691
-
692
-
693
- ///// <summary>
694
- ///// Publishes the node.
695
- ///// </summary>
696
- ///// <param name="Documents">The documents.</param>
697
- //[Obsolete("Please use: umbraco.content.UpdateDocumentCache", true)]
698
- //public virtual void PublishNode(List<Document> Documents)
699
- //{
700
-
701
- // UpdateDocumentCache(Documents);
702
- //}
703
-
704
-
705
-
706
- ///// <summary>
707
- ///// Publishes the node.
708
- ///// </summary>
709
- ///// <param name="d">The document.</param>
710
- //[Obsolete("Please use: umbraco.content.UpdateDocumentCache", true)]
711
- //public virtual void PublishNode(Document d)
712
- //{
713
-
714
- // UpdateDocumentCache(d);
715
- //}
716
-
717
-
718
639
/// <summary>
719
640
/// Occurs when [before document cache update].
720
641
/// </summary>
@@ -932,9 +853,10 @@ internal bool IsXmlQueuedForPersistenceToFile
932
853
RemoveXmlFilePersistenceQueue ( ) ;
933
854
}
934
855
}
935
- catch
856
+ catch ( Exception ex )
936
857
{
937
858
// Nothing to catch here - we'll just persist
859
+ LogHelper . Error < content > ( "An error occurred checking if xml file is queued for persistence" , ex ) ;
938
860
}
939
861
}
940
862
}
@@ -1036,22 +958,8 @@ private static void InitContentDocument(XmlDocument xmlDoc, string dtd)
1036
958
/// </summary>
1037
959
private XmlDocument LoadContentFromDatabase ( )
1038
960
{
1039
- // Alex N - 2010 06 - Very generic try-catch simply because at the moment, unfortunately, this method gets called inside a ThreadPool thread
1040
- // and we need to guarantee it won't tear down the app pool by throwing an unhandled exception
1041
961
try
1042
962
{
1043
- // Moved User to a local variable - why are we causing user 0 to load from the DB though?
1044
- // Alex N 20100212
1045
- User staticUser = null ;
1046
- try
1047
- {
1048
- staticUser = User . GetCurrent ( ) ; //User.GetUser(0);
1049
- }
1050
- catch
1051
- {
1052
- /* We don't care later if the staticUser is null */
1053
- }
1054
-
1055
963
// Try to log to the DB
1056
964
LogHelper . Info < content > ( "Loading content from database..." ) ;
1057
965
@@ -1235,19 +1143,10 @@ internal void PersistXmlToFile(XmlDocument xmlDoc)
1235
1143
{
1236
1144
if ( xmlDoc != null )
1237
1145
{
1238
- Trace . Write ( string . Format ( "Saving content to disk on thread '{0}' (Threadpool? {1})" ,
1239
- Thread . CurrentThread . Name , Thread . CurrentThread . IsThreadPoolThread ) ) ;
1240
-
1241
- // Moved the user into a variable and avoided it throwing an error if one can't be loaded (e.g. empty / corrupt db on initial install)
1242
- User staticUser = null ;
1243
- try
1244
- {
1245
- staticUser = User . GetCurrent ( ) ;
1246
- }
1247
- catch
1248
- {
1249
- }
1250
-
1146
+ LogHelper . Debug < content > ( "Saving content to disk on thread '{0}' (Threadpool? {1})" ,
1147
+ ( ) => Thread . CurrentThread . Name ,
1148
+ ( ) => Thread . CurrentThread . IsThreadPoolThread ) ;
1149
+
1251
1150
try
1252
1151
{
1253
1152
Stopwatch stopWatch = Stopwatch . StartNew ( ) ;
@@ -1263,23 +1162,20 @@ internal void PersistXmlToFile(XmlDocument xmlDoc)
1263
1162
}
1264
1163
1265
1164
xmlDoc . Save ( UmbracoXmlDiskCacheFileName ) ;
1266
-
1267
- Trace . Write ( string . Format ( "Saved content on thread '{0}' in {1} (Threadpool? {2})" ,
1268
- Thread . CurrentThread . Name , stopWatch . Elapsed ,
1269
- Thread . CurrentThread . IsThreadPoolThread ) ) ;
1270
-
1271
- LogHelper . Debug < content > ( string . Format ( "Xml saved in {0}" , stopWatch . Elapsed ) ) ;
1165
+
1166
+ LogHelper . Debug < content > ( "Saved content on thread '{0}' in {1} (Threadpool? {2})" ,
1167
+ ( ) => Thread . CurrentThread . Name ,
1168
+ ( ) => stopWatch . Elapsed ,
1169
+ ( ) => Thread . CurrentThread . IsThreadPoolThread ) ;
1272
1170
}
1273
1171
catch ( Exception ee )
1274
1172
{
1275
1173
// If for whatever reason something goes wrong here, invalidate disk cache
1276
1174
DeleteXmlCache ( ) ;
1277
-
1278
- Trace . Write ( string . Format (
1175
+
1176
+ LogHelper . Error < content > ( string . Format (
1279
1177
"Error saving content on thread '{0}' due to '{1}' (Threadpool? {2})" ,
1280
- Thread . CurrentThread . Name , ee . Message , Thread . CurrentThread . IsThreadPoolThread ) ) ;
1281
-
1282
- LogHelper . Error < content > ( "Xml wasn't saved" , ee ) ;
1178
+ Thread . CurrentThread . Name , ee . Message , Thread . CurrentThread . IsThreadPoolThread ) , ee ) ;
1283
1179
}
1284
1180
}
1285
1181
}
@@ -1288,36 +1184,29 @@ internal void PersistXmlToFile(XmlDocument xmlDoc)
1288
1184
/// <summary>
1289
1185
/// Marks a flag in the HttpContext so that, upon page execution completion, the Xml cache will
1290
1186
/// get persisted to disk. Ensure this method is only called from a thread executing a page request
1291
- /// since umbraco.presentation.requestModule is the only monitor of this flag and is responsible
1187
+ /// since UmbracoModule is the only monitor of this flag and is responsible
1292
1188
/// for enacting the persistence at the PostRequestHandlerExecute stage of the page lifecycle.
1293
1189
/// </summary>
1294
1190
private void QueueXmlForPersistence ( )
1295
1191
{
1296
- /* Alex Norcliffe 2010 06 03 - removing all launching of ThreadPool threads, instead we just
1297
- * flag on the context that the Xml should be saved and an event in the requestModule
1298
- * will check for this and call PersistXmlToFile() if necessary */
1192
+ //if this is called outside a web request we cannot queue it.
1193
+
1299
1194
if ( HttpContext . Current != null )
1300
1195
{
1301
1196
HttpContext . Current . Application . Lock ( ) ;
1302
- if ( HttpContext . Current . Application [ PersistenceFlagContextKey ] != null )
1303
- HttpContext . Current . Application . Add ( PersistenceFlagContextKey , null ) ;
1304
- HttpContext . Current . Application [ PersistenceFlagContextKey ] = DateTime . UtcNow ;
1305
- HttpContext . Current . Application . UnLock ( ) ;
1306
- }
1307
- else
1308
- {
1309
- //// Save copy of content
1310
- if ( UmbracoSettings . CloneXmlCacheOnPublish )
1197
+ try
1311
1198
{
1312
- XmlDocument xmlContentCopy = CloneXmlDoc ( _xmlContent ) ;
1313
-
1314
- ThreadPool . QueueUserWorkItem (
1315
- delegate { PersistXmlToFile ( xmlContentCopy ) ; } ) ;
1199
+ if ( HttpContext . Current . Application [ PersistenceFlagContextKey ] != null )
1200
+ {
1201
+ HttpContext . Current . Application . Add ( PersistenceFlagContextKey , null ) ;
1202
+ }
1203
+ HttpContext . Current . Application [ PersistenceFlagContextKey ] = DateTime . UtcNow ;
1316
1204
}
1317
- else
1318
- ThreadPool . QueueUserWorkItem (
1319
- delegate { PersistXmlToFile ( ) ; } ) ;
1320
- }
1205
+ finally
1206
+ {
1207
+ HttpContext . Current . Application . UnLock ( ) ;
1208
+ }
1209
+ }
1321
1210
}
1322
1211
1323
1212
internal DateTime GetCacheFileUpdateTime ( )
0 commit comments