[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.caching

Problem with CacheDependency - Fires twice

Martin Millar

5/26/2005 3:49:00 PM

Hi

I am trying to load 2 large xml files into 2 datasets and store them in
Cache. The CacheDependency is linked to 3rd file which is produced after the
xml files are written.

What happens is that the callback routine is called twice for each
dependency when the dependancy file is altered. So I read the xml files in
twice - not good.

If I stick to one dataset it's fine

All my code is in global.asax

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
_Cache = HttpContext.Current.Cache
_OrderDetailFile =
ConfigurationSettings.AppSettings("SAPORDERDETAILFILENAME")
_OrderAssignFile =
ConfigurationSettings.AppSettings("SAPORDERASSIGNFILE")
_DependencyFile = ConfigurationSettings.AppSettings("DEPENDENCYFILE")

Call RefreshOrderData("SAPORDER", Nothing,
CacheItemRemovedReason.Expired)
Call RefreshAssignData("SAPASSIGN", Nothing,
CacheItemRemovedReason.Expired)

End Sub


Public Sub RefreshOrderData(ByVal key As String, ByVal value As Object,
ByVal reason As Caching.CacheItemRemovedReason)

Dim ds As DataSet
ds = ReadOrderXMLFile() ' read xml file
If Not ds Is Nothing Then
_Cache.Insert("SAPORDER", ds, New
CacheDependency(_DependencyFile), _
Cache.NoAbsoluteExpiration,
Cache.NoSlidingExpiration, _
CacheItemPriority.Default, _
New CacheItemRemovedCallback(AddressOf
Me.RefreshOrderData))
End If
End Sub

'================================
Public Sub RefreshAssignData(ByVal key As String, ByVal value As Object,
ByVal reason As Caching.CacheItemRemovedReason)

Dim ds As DataSet
ds = ReadAssignXMLFile()
If Not ds Is Nothing Then
_Cache.Insert("SAPASSIGN", ds, New
CacheDependency(_DependencyFile), _
Cache.NoAbsoluteExpiration,
Cache.NoSlidingExpiration, _
CacheItemPriority.Default, _
New CacheItemRemovedCallback(AddressOf
Me.RefreshAssignData))
End If
End Sub




--
MM
1 Answer

Alvin Bruney [ASP.NET MVP]

5/29/2005 3:26:00 AM

0

why can''t you set and check a flag that tells u if the read is a duplicate.
this seems like a good quick fix to me

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc, Amazon.com etc
"Martin Millar" <barney@newsgroups.nospam> wrote in message
news:674F2095-409F-44FE-BD92-7D82CEE4DD89@microsoft.com...
> Hi
>
> I am trying to load 2 large xml files into 2 datasets and store them in
> Cache. The CacheDependency is linked to 3rd file which is produced after
> the
> xml files are written.
>
> What happens is that the callback routine is called twice for each
> dependency when the dependancy file is altered. So I read the xml files in
> twice - not good.
>
> If I stick to one dataset it''s fine
>
> All my code is in global.asax
>
> Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
> '' Fires when the application is started
> _Cache = HttpContext.Current.Cache
> _OrderDetailFile =
> ConfigurationSettings.AppSettings("SAPORDERDETAILFILENAME")
> _OrderAssignFile =
> ConfigurationSettings.AppSettings("SAPORDERASSIGNFILE")
> _DependencyFile =
> ConfigurationSettings.AppSettings("DEPENDENCYFILE")
>
> Call RefreshOrderData("SAPORDER", Nothing,
> CacheItemRemovedReason.Expired)
> Call RefreshAssignData("SAPASSIGN", Nothing,
> CacheItemRemovedReason.Expired)
>
> End Sub
>
>
> Public Sub RefreshOrderData(ByVal key As String, ByVal value As Object,
> ByVal reason As Caching.CacheItemRemovedReason)
>
> Dim ds As DataSet
> ds = ReadOrderXMLFile() '' read xml file
> If Not ds Is Nothing Then
> _Cache.Insert("SAPORDER", ds, New
> CacheDependency(_DependencyFile), _
> Cache.NoAbsoluteExpiration,
> Cache.NoSlidingExpiration, _
> CacheItemPriority.Default, _
> New CacheItemRemovedCallback(AddressOf
> Me.RefreshOrderData))
> End If
> End Sub
>
> ''================================
> Public Sub RefreshAssignData(ByVal key As String, ByVal value As Object,
> ByVal reason As Caching.CacheItemRemovedReason)
>
> Dim ds As DataSet
> ds = ReadAssignXMLFile()
> If Not ds Is Nothing Then
> _Cache.Insert("SAPASSIGN", ds, New
> CacheDependency(_DependencyFile), _
> Cache.NoAbsoluteExpiration,
> Cache.NoSlidingExpiration, _
> CacheItemPriority.Default, _
> New CacheItemRemovedCallback(AddressOf
> Me.RefreshAssignData))
> End If
> End Sub
>
>
>
>
> --
> MM