473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Examine items in the ASP.NET cache added using the OutputCache directive

Hi,

Does anyone know how to examine items in the ASP.NET cache that are added
using the OutputCache directive in framework 1.1

i.e.

<%@ OutputCache Duration="300" VaryByParam="None"
VaryByCustom="cmscontrol,cmsrole"%>

By examine I mean see their value, key and expiration time.

Cheers Ed.
Nov 19 '05 #1
1 2207
In the end I cludged it using a bit of hacked together reflection:

<%@ Page language="c#" AutoEventWireup="false" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Reflection" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Web.Caching" %>
<script runat=server>
override protected void OnInit(EventArgs e)
{
this.Load += new System.EventHandler(this.Page_Load);
base.OnInit(e);
}

private const string row = "<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>";
private void Page_Load(object sender, System.EventArgs e)
{
StringBuilder outHtml = new StringBuilder(512);
outHtml.Append("<table cellpadding=0 cellspacing=0 border=1>");
outHtml.Append("<tr><td>Key</td><td>Value</td><td>Type</td></tr>");

// Grap the CacheInternal cache object from Cache using reflection
Type cacheType = Cache.GetType();
FieldInfo fieldCacheInternal = cacheType.GetField("_cacheInternal",
BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Instance);
Object cacheInternal = fieldCacheInternal.GetValue(Cache);
Hashtable _entries = (Hashtable)
cacheInternal.GetType().GetField("_entries", BindingFlags.DeclaredOnly |
BindingFlags.NonPublic | BindingFlags.Instance).GetValue(cacheInternal);

outHtml.Append("<tr><td colspan=3>Count:" + _entries.Count + "</td>");
foreach (DictionaryEntry entry in _entries)
{
Type typeCacheEntry = entry.Value.GetType();
FieldInfo fldKey = typeCacheEntry.BaseType.GetField("_key",
BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Instance);
FieldInfo fldValue = typeCacheEntry.GetField("_value",
BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Instance);

outHtml.Append(string.Format(row,
fldKey.GetValue(entry.Value).ToString(),
fldValue.GetValue(entry.Value).ToString(),
fldValue.GetValue(entry.Value).GetType().ToString( )));
}

literalOut.Text = outHtml.ToString();
}
</script>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Cache</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Literal id="literalOut" runat="server"></asp:Literal>
</form>
</body>
</HTML>

Ed.
"Edward Wilde" <ew****@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
Hi,

Does anyone know how to examine items in the ASP.NET cache that are added
using the OutputCache directive in framework 1.1

i.e.

<%@ OutputCache Duration="300" VaryByParam="None"
VaryByCustom="cmscontrol,cmsrole"%>

By examine I mean see their value, key and expiration time.

Cheers Ed.

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jose Marciano | last post by:
Hello. Could someone tell me the way(s) of doing cache in old ASP pages? What i really wanted was to keep in cache for some time the HTML generated by an ASP page (something like the...
2
by: Jason Huang | last post by:
Hi, Kind of spending too much time on the no-cache issue and found out something like <% Response.CacheControl = "no-cache" %>. In my ASP.Net, a C# .aspx file, where do I put the <%...
6
by: Tom Kiefer | last post by:
Question: If I have an ASP.NET User Control which defines/exposes a property that the page can use to specify a mode or data subset for the control to use, is there a way to tell the @OutputCache...
4
by: Proc | last post by:
I am hoping someone here can point me in the right direction with a problem my user's are experiencing. Here is what is happening: I have an ASP.NET application that several users will use at...
11
by: Steve Franks | last post by:
I see several reference to using the ASP.NET 2.0 Cache object in C# where the documentation just shows snippets like this: if (Cache == null) ... do something However when I use this code in a...
2
by: jack | last post by:
Now here i have a doubt the explorer maintains the cache for 300 seconds when the code is in html code like the one which is below :- <%@ OutputCache Duration="300" VaryByParam="none" %> But...
1
by: stupy1 | last post by:
I have a number of relatively static pages with a multivew control on each of them. What I'd like to do is cache these pages with either the outputcache directive or cache API. I've tried the...
0
by: Pete Griffiths | last post by:
Hi folks, I have an infuriating problem. I have a number of pages that I want to cache server-side only, using varybycustom. I have implemented a GetVaryByCustomString in my global.asax. I am...
4
by: RedHair | last post by:
Development: Windows 2003 Production :Windows 2003 ASP.NET 2.0 + C# I want to disable the cache feature of all pages in dev but enable it in production environments. What's the solution? If...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.