首页 > 编程 > .NET > 正文

ASP.NET实现Cache浏览器的管理

2024-07-10 12:55:00
字体:
来源:转载
供稿:网友
对cache进行浏览并管理。
  
  <%@ page language="<a href="http://dev.21tx.com/dotnet/csharp/" target="_blank">c#</a>" 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://<a href="http://dev.21tx.com/web/asp/" target="_blank">asp</a>alliance.com/aldotnet/examples/cacheviewer.aspx
  //http://scottwater.com
  private void page_load(object sender, system.eventargs e)
  {
   if(!ispostback)
   {
   hlrefresh.navigateurl = request.rawurl;
   bindgrid();
   }
  }
  
  //绑定到<a href="http://dev.21tx.com/dotnet/aspnet/datagrid/" target="_blank">datagrid</a>
  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)
  {
   hy<a href="http://dev.21tx.com/web/perl/" target="_blank">perl</a>ink 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" 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控件,是为了方便本站的管理,其它则不必这样用。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表