SQLCacheDependency not notifying

Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Feb 2009
Posts: 7
Reputation: yisman is an unknown quantity at this point 
Solved Threads: 0
yisman yisman is offline Offline
Newbie Poster

SQLCacheDependency not notifying

 
0
  #1
Jun 23rd, 2009
Hi everybody
I have coded a LINQ SiteMapProvider for my ASP.NET site. The site pages info is stored in a MSSQL database.
When I make changes to the SitePAges table, the SiteMap does not reset. Here is my code
  1. Public Overrides Function BuildSiteMap() As System.Web.SiteMapNode
  2. If RootMapNode IsNot Nothing Then Return RootMapNode
  3. dcx = New GrabdayDataContext
  4. RootMapNode = Nothing
  5. Dim SitePages = From q In dcx.SitePages Where q.ParentID Is Nothing
  6. Dim cmd As New SqlCommand("select sitepageid, parentid from SitePages", New SqlConnection(ConfigurationManager.ConnectionStrings("Grabday").ConnectionString))
  7. Dim dependency = New SqlCacheDependency(cmd)
  8. RootMapNode = SitePageNode(SitePages.FirstOrDefault)
  9. AddNode(RootMapNode, Nothing)
  10. AddChildNodes(RootMapNode, SitePages.FirstOrDefault)
  11. HttpRuntime.Cache.Insert(_cacheDependencyName, New Object(), dependency, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, New CacheItemRemovedCallback(AddressOf OnSiteMapChanged))
  12. Return RootMapNode
  13. End Function
  14.  
  15. Sub OnSiteMapChanged()
  16. Clear()
  17. End Sub
If i understand correctly, the OnSiteMapChanged sub is supposed to run as soon as the tableset becomes invalidated, which somehow never occurs. I put dependenct.start and dependency.stop in my global.asax file in app_start and app_end respectively

My debugging shows that the "Insert" code to the cache does occur, though i dont understand why it is needed (the code was ported from a sqlsitemapprovider). doesnt asp.net cache the data on its own? it definetly does.

Can someone help me get my data invalidated or whatever?
my db show that Is_Broker_Enabled is on
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,417
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 429
adatapost's Avatar
adatapost adatapost is offline Offline
Nearly a Posting Maven

Re: SQLCacheDependency not notifying

 
0
  #2
Jun 23rd, 2009
Welcome.

Your code is incomplete for any suggestion. Please read this Article.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 7
Reputation: yisman is an unknown quantity at this point 
Solved Threads: 0
yisman yisman is offline Offline
Newbie Poster

Re: SQLCacheDependency not notifying

 
0
  #3
Jun 23rd, 2009
hi
soory, i havent meant to skimp. I just thought to keep the code to only waht is necessary.
I am going over the article you sent me, meanwhile, here is the complete Provider Class
Please point out where im misatking
thanks
  1. Imports System.Collections.Specialized
  2. Imports System.Data.SqlClient
  3. Imports System.Configuration
  4. Imports System.Web.Caching
  5. Imports System.Collections.Generic
  6.  
  7. Public Class LINQSiteMapProvider
  8. Inherits StaticSiteMapProvider
  9. Dim dcx As GrabdayDataContext
  10. Dim RootMapNode As SiteMapNode
  11. Dim UserID As Integer
  12. Const _cacheDependencyName As String = "__SiteMapCacheDependency"
  13.  
  14.  
  15. Public Overrides Sub Initialize(ByVal name As String, ByVal attributes As System.Collections.Specialized.NameValueCollection)
  16. MyBase.Initialize(name, attributes)
  17. dcx = New GrabdayDataContext
  18. End Sub
  19.  
  20. Public Overrides Function BuildSiteMap() As System.Web.SiteMapNode
  21. If RootMapNode IsNot Nothing Then Return RootMapNode
  22. dcx = New GrabdayDataContext
  23. RootMapNode = Nothing
  24. Dim SitePages = From q In dcx.SitePages Where q.ParentID Is Nothing
  25. Dim cmd As New SqlCommand("select sitepageid, parentid from SitePages", New SqlConnection(ConfigurationManager.ConnectionStrings("Grabday").ConnectionString))
  26. Dim dependency = New SqlCacheDependency(cmd)
  27. RootMapNode = SitePageNode(SitePages.FirstOrDefault)
  28. AddNode(RootMapNode, Nothing)
  29. AddChildNodes(RootMapNode, SitePages.FirstOrDefault)
  30. HttpRuntime.Cache.Insert(_cacheDependencyName, New Object(), dependency, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, New CacheItemRemovedCallback(AddressOf OnSiteMapChanged))
  31. Return RootMapNode
  32. End Function
  33.  
  34. Protected Overrides Function GetRootNodeCore() As System.Web.SiteMapNode
  35. BuildSiteMap()
  36. Return RootMapNode
  37. End Function
  38.  
  39. Sub AddChildNodes(ByVal ParentNode As SiteMapNode, ByVal ParentPage As SitePage)
  40. Dim childs = From q In dcx.SitePages Where q.ParentID = ParentPage.SitePageID
  41. Dim NewNode As SiteMapNode
  42. For Each sp In childs
  43. NewNode = SitePageNode(sp)
  44. AddNode(NewNode, ParentNode)
  45. AddChildNodes(NewNode, sp)
  46. Next
  47. If ParentPage.PageName = "OrdersByStatus" Then
  48. Dim statusses = From q In dcx.OrderEvents Select q.Brief Distinct
  49. Dim roles As String() = {}
  50. Dim nvc As New NameValueCollection
  51. nvc.Item("PageName") = "Orders"
  52. For Each os As String In statusses
  53. NewNode = New SiteMapNode(Me, os & "Orders", "~\Admin\Orders.aspx?Status=" & os, os & " Orders", os & " Orders", roles, nvc, New NameValueCollection, "")
  54. AddNode(NewNode, ParentNode)
  55. Next
  56. End If
  57. End Sub
  58.  
  59. Function SitePageNode(ByVal SitePage As SitePage) As SiteMapNode
  60. Dim nvc As New NameValueCollection
  61. nvc.Item("PageName") = SitePage.PageName
  62. Dim roles As String() = {}
  63. Return New SiteMapNode(Me, SitePage.SitePageID, If(SitePage.URL, "~\Admin\Menu.aspx" & "?ID=" & SitePage.SitePageID), SitePage.Title, SitePage.Description, roles, nvc, New NameValueCollection, "")
  64. End Function
  65.  
  66. Sub OnSiteMapChanged()
  67. Clear()
  68. End Sub
  69.  
  70. End Class
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,417
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 429
adatapost's Avatar
adatapost adatapost is offline Offline
Nearly a Posting Maven

Re: SQLCacheDependency not notifying

 
0
  #4
Jun 23rd, 2009
Let's see web.config provider entry.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC