⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cachecallback.aspx

📁 asp.net技术内幕的书配源码
💻 ASPX
字号:
<Script Runat="Server">

Public Shared onRemove As CacheItemRemovedCallback

Sub ItemRemoved( _
  strItemKey As String, _
  objItemValue As Object, _
  objRemovedReason As CacheItemRemovedReason )

  Dim strLogEntry As String

  strLogEntry = "Item with value " & objItemValue.ToString() 
  strLogEntry &= " removed at " & Now.ToString( "T" )
  strLogEntry &= " because of " & objRemovedReason.ToString()
  If Application( "CacheLog" ) Is Nothing Then
    Application( "CacheLog" ) = New ArrayList
  End If
  Application( "CacheLog" ).Add( strLogEntry )
  Beep
End Sub

Sub btnAddCache_Click( s As Object, e As EventArgs )
    onRemove =  New CacheItemRemovedCallback( AddressOf ItemRemoved )
    Cache.Insert( "myItem", _
                   txtNewValue.Text, _
                   Nothing, _
                   Now.AddSeconds( 10 ), _
                   Cache.NoSlidingExpiration, _
                   CacheItemPriority.High, _
                   onRemove )
End Sub

Sub btnRemoveCache_Click( s As Object, e As EventArgs )
  Cache.Remove( "myItem" )
End Sub

Sub Page_PreRender( s As Object, e As EventArgs )
  dgrdCacheLog.DataSource = Application( "CacheLog" )
  dgrdCacheLog.Databind()
End Sub

</Script>

<html>
<head><title>CacheCallback.aspx</title></head>
<body>
<form Runat="Server">

<h2>Cache Log</h2>
<asp:DataGrid
  ID="dgrdCacheLog"
  CellPadding="8"
  Runat="Server" />
<p>
<asp:TextBox
  id="txtNewValue"
  Runat="Server" />
<p>
<asp:Button
  id="btnAddCache"
  Text="Add To Cache!"
  OnClick="btnAddCache_Click"
  Runat="Server" />

<asp:Button
  id="btnRemoveCache"
  Text="Remove From Cache!"
  OnClick="btnRemoveCache_Click"
  Runat="Server" />

<asp:Button
  Text="Refresh Page!"
  Runat="Server" />

</form>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -