Manage cache browsers using ASP. NET

Source: Internet
Author: User
Browse and manage the 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 ();
}
}

// Bind to the <a href = "http://dev.21tx.com/dotnet/aspnet/datagrid/" target = "_ blank"> DataGrid </a>
Private void bindgrid ()
{
// Create an arraylist to save the cacheditem Information
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 ();
}

// Delete the cache entry
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 ");
// Make sure that this item is found
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 manager </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">
Browse and delete Cache
<Br/>
Quantity:
<Asp: literal id = "litcount" runat = "server"> </ASP: literal>
<Br/>
<Asp: linkbutton id = "lbremoveall" onclick = "lbremoveall_click" runat = "server"> clear all cache items </ASP: linkbutton>
<Br/>
<Asp: hyperlink id = "hlrefresh" text = "refresh" runat = "server"> </ASP: hyperlink>
<Br/>
<Asp: DataGrid id = "dgcacheditems" runat = "server" onitemcommand = "grid_itemcommand"
Autogeneratecolumns = "false" onitemcreated = "grid_created">
<Headerstyle cssclass = "Header"> <Columns>
<Asp: templatecolumn headertext = "quantity">
<Itemtemplate>
<Asp: literal id = "counter" runat = "server"/>
</Itemtemplate>
</ASP: templatecolumn>
<Asp: templatecolumn headertext = "key">
<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 = "type">
<Itemtemplate>
<Asp: literal id = "cacheitemdatatype" runat = "server"
TEXT = '<% # (cacheditem) (container. dataitem). cachetype %>'/>
</Itemtemplate>
</ASP: templatecolumn>
<Asp: templatecolumn headertext = "delete">
<Itemtemplate>
<Asp: linkbutton id = "removebutton" text = "delete" commandname = "removefromcache"
Runat = "server"/>
</Itemtemplate>
</ASP: templatecolumn>
</Columns>
</ASP: DataGrid>
</Form>
</Body>
</Html>

Note: The hyperlink web control is used in the DataGrid to facilitate the management of this site. Other components do not need to be used in this way.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.