I asked the following in the microsoft.public.dotnet.framework.aspnet.caching newsgroup but have not heard a response. i saw your article on caching and thought that you might have an answer...
I am trying to implement a callback when a cache item expires (or is
removed). Below is sample code from my page that does just that...
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If (Not Page.IsPostBack) Then
Dim eventLogEntry As New EventLog("Application", ".",
"Caching")
eventLogEntry.WriteEntry("MyCachedItem put in cache.",
EventLogEntryType.Information)
Cache.Add("MyCachedItem", TextBox1.Text, Nothing, _
Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(20), _
CacheItemPriority.Low, New
CacheItemRemovedCallback(AddressOf CacheRemoved))
End If
End Sub
Private Sub CacheRemoved(ByVal key As String, ByVal value As Object,
ByVal reason As CacheItemRemovedReason)
Dim eventLogEntry As New EventLog("Application", ".", "Caching")
eventLogEntry.WriteEntry(key + " expired in cache.",
EventLogEntryType.Information)
End Sub
I am setting the cache timeout to 20 seconds...but when I look at the event
log, I don't see the expiration eventlog item in 20 second. I see different
timespans (not the 20 seconds that I am expecting) when the callback is
actually called...
Date: 9/29/2005 Time: 4:33:40 PM MyCachedItem put in cache.
Date: 9/29/2005 Time: 4:35:00 PM MyCachedItem expired in cache.
Date: 9/29/2005 Time: 4:42:09 PM MyCachedItem put in cache.
Date: 9/29/2005 Time: 4:43:00 PM MyCachedItem expired in cache.
Date: 9/29/2005 Time: 4:44:35 PM MyCachedItem put in cache.
Date: 9/29/2005 Time: 4:46:00 PM MyCachedItem expired in cache.
Am I doing something wrong? Or is this something to do with the GC (is that
how cache items are expired)? Thanks for any help!!
Steven A Smith
President, AspAlliance LLC
CIO, Lake Quincy Media, LLC