Subscribe to umbraco events, say in Application_Start function in Global.asax
content.AfterRefreshContent += new content.RefreshContentEventHandler(content_AfterRefreshContent); content.AfterUpdateDocumentCache += new content.DocumentCacheEventHandler(content_AfterRefreshContent); content.AfterClearDocumentCache += new content.DocumentCacheEventHandler(content_AfterRefreshContent);
Refresh linq2umbraco cache in event handler:
void content_AfterRefreshContent(umbraco.cms.businesslogic.web.Document sender, CancelEventArgs e) { var ctx = ContainerProvider.RequestLifetime.Resolve<IMyDataContext>(); var dp = ctx.DataProvider as NodeDataProvider; if (dp != null) dp.Flush(); }
It is not umbraco specific. ContainerProvider comes from Autofac, dependency injection framework, we use this thing to get reference to data context (that implements IMyDataContext interface).
unpublished items stay until web.config touched
linq2umbraco keeps including unpublished nodes in the list until I touch web.config
Is there a way to make refresh automatically?
Thanks!
Did anyone encounter this issue? I've been searching for third party umbraco package for cache refreshing but couldn't find one.
At least, how long umbraco linq cache lasts after item being unpublished/deleted?
I'm saying about linq2umbraco problem because node factorty works correctly (it does not return such nodes)
Thanks everyone for great zen style help!
Solution is as follows:
Subscribe to umbraco events, say in Application_Start function in Global.asax
content.AfterRefreshContent += new content.RefreshContentEventHandler(content_AfterRefreshContent);
content.AfterUpdateDocumentCache += new content.DocumentCacheEventHandler(content_AfterRefreshContent);
content.AfterClearDocumentCache += new content.DocumentCacheEventHandler(content_AfterRefreshContent);
Refresh linq2umbraco cache in event handler:
void content_AfterRefreshContent(umbraco.cms.businesslogic.web.Document sender, CancelEventArgs e)
{
var ctx = ContainerProvider.RequestLifetime.Resolve<IMyDataContext>();
var dp = ctx.DataProvider as NodeDataProvider;
if (dp != null)
dp.Flush();
}
Hi eugenekr, im trying to do this too, but where comes "ContainerProvider" from?
Do i need a reference for using it?
Hi Amigo!
It is not umbraco specific. ContainerProvider comes from Autofac, dependency injection framework, we use this thing to get reference to data context (that implements IMyDataContext interface).
is working on a reply...