Cache浏览器

类别:.NET开发 点击:0 评论:0 推荐:
Cache浏览器
作者:孟宪会 出自:【孟宪会之精彩世界】 发布日期:2004年6月2日 9点38分8秒

对Cache进行浏览并管理。

<%@ Page Language="C#" EnableViewState = "true"%> <%@ import Namespace="System" %> <%@ import Namespace="System.Configuration" %> <%@ import Namespace="System.Collections" %> <%@ import Namespace="System.Collections.Specialized" %> <%@ import Namespace="System.Data" %> <script runat="server"> //http://aspalliance.com/aldotnet/examples/cacheviewer.aspx //http://scottwater.com private void Page_Load(object sender, System.EventArgs e) { if(!IsPostBack) { hlRefresh.NavigateUrl = Request.RawUrl; BindGrid(); } } //绑定到DataGrid private void BindGrid() { //创建arraylist来保存cacheditem信息 ArrayList al = new ArrayList(); IDictionaryEnumerator CacheEnum = Cache.GetEnumerator(); while (CacheEnum.MoveNext()) { al.Add(new CachedItem(CacheEnum.Key.ToString(),CacheEnum.Value.GetType().ToString())); } litCount.Text = al.Count.ToString(); dgCachedItems.DataSource = al; dgCachedItems.DataBind(); } //删除Cache项 protected void Grid_ItemCommand(object sender, DataGridCommandEventArgs e) { HyperLink l = (HyperLink)e.Item.FindControl("CacheItemName"); //确保我们找到了该项 if(l != null) { Cache.Remove(l.Text); } this.BindGrid(); } protected void Grid_Created(object sender, DataGridItemEventArgs e) { if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { ((Literal)e.Item.FindControl("Counter")).Text = (e.Item.ItemIndex + 1).ToString(); } } private class CachedItem { public CachedItem(){} public CachedItem(string key, string type) { this.CacheKey = key; this.CacheType = type; } private string _cacheKey; public string CacheKey { get {return this._cacheKey;} set {this._cacheKey = value;} } private string _cacheType; public string CacheType { get {return this._cacheType;} set {this._cacheType = value;} } } //Remove All void lbRemoveAll_Click(object sender, EventArgs e) { IDictionaryEnumerator CacheEnum = Cache.GetEnumerator(); while (CacheEnum.MoveNext()) { Cache.Remove(CacheEnum.Key.ToString()); } BindGrid(); } </script> <html> <head> <title>Cache管理器</title> <style> TD,A,P,SPAN {font-size:9pt;} .Header {background-color:#EDEDED;text-align:center;font-weight:bold;} </style> </head> <body > <form runat="server"> 浏览、删除缓存 <br/> 数量: <asp:Literal id="litCount" runat="server"></asp:Literal> <br/> <asp:LinkButton id="lbRemoveAll" onclick="lbRemoveAll_Click" runat="server">清除全部缓存项</asp:LinkButton> <br/> <asp:HyperLink id="hlRefresh" Text="刷新" Runat="server"></asp:HyperLink> <br/><br/> <asp:DataGrid id="dgCachedItems" runat="server" OnItemCommand="Grid_ItemCommand" AutoGenerateColumns="False" OnItemCreated="Grid_Created"> <HeaderStyle CssClass="Header"></HeaderStyle> <Columns> <asp:TemplateColumn HeaderText="数量"> <ItemTemplate> <asp:Literal id="Counter" runat="server" /> </ItemTemplate> </asp:TemplateColumn> <asp:TemplateColumn HeaderText="键"> <ItemTemplate> <asp:HyperLink id="CacheItemName" runat="server" Target="_blank" Text='<%# ((CachedItem)(Container.DataItem)).CacheKey %>' NavigateUrl = '<%# ((CachedItem)(Container.DataItem)).CacheKey %>'/> </ItemTemplate> </asp:TemplateColumn> <asp:TemplateColumn HeaderText="类型"> <ItemTemplate> <asp:Literal id="CacheItemDataType" runat="server" text='<%# ((CachedItem)(Container.DataItem)).CacheType %>' /> </ItemTemplate> </asp:TemplateColumn> <asp:TemplateColumn HeaderText="删除"> <ItemTemplate> <asp:LinkButton ID="RemoveButton" Text="删除" CommandName="RemoveFromCache" runat="server" /> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid> </form> </body> </html>

说明:DataGrid中用到了HyperLink Web控件,是为了方便本站的管理,其它则不必这样用。

本文地址:http://com.8s8s.com/it/it43220.htm