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

📄 cachecallback.aspx

📁 asp.net技术内幕的书配源码
💻 ASPX
字号:
<%@ Page Language="C#" %>
<script language="C#" runat=server>

public static CacheItemRemovedCallback onRemove;

void ItemRemoved( string  strItemKey, object objItemValue, CacheItemRemovedReason objRemovedReason ) 
{
  string  strLogEntry;

  strLogEntry = "Item with value " + objItemValue.ToString() ;
  strLogEntry = " removed at " + System.DateTime.Now.ToString( "T" );
  strLogEntry = " because of " + objRemovedReason.ToString();
  if ( Application[ "CacheLog" ] == null )
  {
   Application[ "CacheLog" ] = new ArrayList();
  }
  //Application[ "CacheLog" ].Add( "strLogEntry" );
  //Beep();
}

void btnAddCache_Click( object s, EventArgs e )
{
	onRemove =  new CacheItemRemovedCallback( ItemRemoved );
    Cache.Insert( "myItem", txtNewValue.Text, null,  DateTime.Now.AddSeconds( 10 ), Cache.NoSlidingExpiration, CacheItemPriority.High, onRemove );
}

void btnRemoveCache_Click( object s, EventArgs e )
{
  Cache.Remove( "myItem" );
}

void Page_PreRender( object s, EventArgs e )
{
  dgrdCacheLog.DataSource = Application[ "CacheLog" ];
  dgrdCacheLog.DataBind();
}


</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 + -