Link to home
Start Free TrialLog in
Avatar of theMightyThor1212
theMightyThor1212

asked on

ASP.Net Cached Objects

hi all

  I cache off objects in my application. They are Classes of data that are used by the pages in my .net Web App. I am pretty sure i expire them or kill them all together by removing them after they are used. None of the objects would exceed more than 2k in data. Is there a way to check the server thru .Net and ask it, how many cached Objects do you have? and what is the size of the cached Objects? They are User Specific Cached Objects, prefixed by user name. I just want a way to see if my application is performing as expected.(The reason i need this is to ensure the Application did cause an Out Of Memory Exception)

Thanks in Advance
Avatar of b1xml2
b1xml2
Flag of Australia image

Yes,

1. System.Web.HttpContext.Current.Cache.Count (anywhere through the system)
2. Me.Page.Cache.Count (points to the same Cache object as in point #1)
ASKER CERTIFIED SOLUTION
Avatar of b1xml2
b1xml2
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of theMightyThor1212
theMightyThor1212

ASKER

thanks alot i think that will do it, i'll let you know and your response is greatly appreciated
Is this for the Immediate Page or would this check to see if cache was still available after application close that created the cache? I'm kinda looking to check for all cached objects on the server not just created by one page after inserting a cache object let say on a page load like the example you provided.

  I am looking for a Check page to see what the web app uses in cache, what size it is and if it is removed from cache or not.
Can i Query the server using this loop or am i missing something here?

i do appreciate your time.
whenever you refer to the Cache object whether it be via #1 or #2, you are referring to only one Cache object. It is global and accessible throughout the application and by all users.

as for the "size" of the object, now that's extremely subjective. How do you measure the size??
I am more than likely looking at .length property or something like that?

  As for Cache object, I didnt seem to find any cache objects running the code side by side with a page that created the cahce, that why i asked if this was a scope issue or is it application wide. I'll have to test it again and see if it returns a count an name.

   I am Using this procedure to insert cache:

    Sub Cache_Obj(ByVal strObjName As String, ByVal objToCache As Object)
        Dim objCache As System.Web.Caching.Cache = System.Web.HttpRuntime.Cache()
        objCache.Insert(strObjName, objToCache, Nothing, DateTime.Now.AddHours(1), TimeSpan.Zero)

    End Sub

I know when the Page i tested loads, it inserts at least two objects into cache. the inserted objects are class objects that hold data items for use thru out the application.
remember that the objects you add are references. so if you add the object and then change it, it will affect the cache.
On this particular test i didn't change anything in cache, just loaded the page which should have revealed a user object available in cache and i didnt see it appear using the loop you gave me.