
Partial Class Cachetest
    Inherits System.Web.UI.Page

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim dependencies As String() = {"Templatedep"}
    Dim d As New Date(Today.Year, Today.Month, Today.Day, 11, 57, 30)
    Dim d1 As New Date(Today.Year, Today.Month, Today.AddDays(1).Day, 2, 59, 50)

    If HttpContext.Current.Cache.Item("Templatedep") Is Nothing Then
      HttpContext.Current.Cache.Insert("Templatedep", DateTime.Now, Nothing, d1, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, Nothing)
    End If

    If HttpContext.Current.Cache.Item("Template3") Is Nothing Then
      HttpContext.Current.Cache.Insert("Template3", DateTime.Now, New CacheDependency(Nothing, dependencies), d, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, AddressOf RemovedCallback)
    End If
  End Sub


  Public Sub RemovedCallback(ByVal key As String, ByVal value As Object, ByVal reason As CacheItemRemovedReason)
  End Sub

  Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Try
      Dim strKey As String = "Templatedep"
      If Context.Cache.Count > 0 Then
        Dim custenum As IDictionaryEnumerator
        custenum = Context.Cache.GetEnumerator()
        custenum.MoveNext()
        Dim i As Integer
        For i = 1 To Context.Cache.Count
          If custenum.Key = strKey Then
            Context.Cache.Remove(strKey)
            Exit For
          End If
          custenum.MoveNext()
        Next
      End If
      Dim d1 As New Date(Today.Year, Today.Month, Today.AddDays(1).Day, 2, 59, 50)
      If HttpContext.Current.Cache.Item("Templatedep") Is Nothing Then
        HttpContext.Current.Cache.Insert("Templatedep", DateTime.Now, Nothing, d1, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, Nothing)
      End If
      Dim dependencies As String() = {"Templatedep"}
      Dim d As New Date(Today.Year, Today.Month, Today.Day, 11, 57, 30)

      If HttpContext.Current.Cache.Item("Template3") Is Nothing Then
        HttpContext.Current.Cache.Insert("Template3", DateTime.Now, New CacheDependency(Nothing, dependencies), d, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, AddressOf RemovedCallback)
      End If
    Catch ex As Exception
    End Try
  End Sub
End Class
