cachedependency not working ?

D

Dave S

Hi,

I'm trying to use cachedependency to refresh a variable when a config
file in the web application changes, but it doesn't seem to work no matter
what I do.
The code is in the global.asax file on the website and is show below.
The delegate function 'refresher' only seems to fire in debug mode.
The example below has been simplified because I actually want to retrieve
values from the config.xml file when it changes but I need to get this
delegate callback working before I can even think of doing that.
Any ideas what I'm doing wrong ?



Public recache As New CacheItemRemovedCallback(AddressOf refresher)
Public appCache As Cache
Public configFile As String


Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
Dim s As String = "START"
Context.Application("TEST") = s

configFile = Server.MapPath("config.xml")

' use this as a trigger to refresh an application variable
appCache = Context.Cache
appCache.Insert("TEST", _
al, _
New CacheDependency(configFile),
Cache.NoAbsoluteExpiration, _
Cache.NoSlidingExpiration, _
CacheItemPriority.Default, _
recache)
End Sub

Sub refresher(ByVal key As String, ByVal value As Object, ByVal reason
As CacheItemRemovedReason)
Dim s As String = "XXX"
Try
appCache.Insert("TEST", _
s, _
New CacheDependency(configFile), _
Cache.NoAbsoluteExpiration, _
Cache.NoSlidingExpiration, _
CacheItemPriority.Default, _
recache)
Catch ex As Exception
s = "FAIL"
End Try
Context.Application.Set("TEST", s)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top