Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display the content of asp.net cache?

We have an asp.net MVC web application which uses the HttpRuntime.Cache
object to keep some static lookup values. We want to be able to monitor what's
being cached in real time to allow us to pinpoint some possible caching issues.

Since this object isn't strongly typed when reading from it, we need to dynamically
cast each entries to it's concrete type.

Most of the cached items are of IEnumerable where T can be any classes we use in our
project or new ones that could eventually be added as the project goes further.
Can someone give me a pointer on how to do this?

Thank you very much.

like image 572
Stéphan Avatar asked May 04 '11 13:05

Stéphan


1 Answers

Use ASP.NET MVC itself.

public ActionResult Index()
{
    return View(HttpRuntime.Cache)
}

and for the view

Html.DisplayForModel()

You will want to use a custom object template (basically take the MVC template and turn off the depth restriction).

http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-3-default-templates.html

On the object template you will want to alter

else if (ViewData.TemplateInfo.TemplateDepth > 1) { %>
    <%= ViewData.ModelMetadata.SimpleDisplayText %>

And change the > 1 to either be a higher number like 5-10 or just completely remove this depth check (I'd probably start with a 5 and go from there).

like image 117
Chris Marisic Avatar answered Oct 11 '22 05:10

Chris Marisic