[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

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
0
theMightyThor1212
Asked:
theMightyThor1212
  • 4
  • 4
1 Solution
 
b1xml2Commented:
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)
0
 
b1xml2Commented:
simple value objects
=============
        Cache.Insert("User", 123)
        For Each item As DictionaryEntry In Cache
            Response.Write(String.Format("<div>{0}: <b>{1}</b></div>", item.Key, item.Value))
        Next
0
 
theMightyThor1212Author Commented:
thanks alot i think that will do it, i'll let you know and your response is greatly appreciated
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
theMightyThor1212Author Commented:
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.
0
 
b1xml2Commented:
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??
0
 
theMightyThor1212Author Commented:
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.
0
 
b1xml2Commented:
remember that the objects you add are references. so if you add the object and then change it, it will affect the cache.
0
 
theMightyThor1212Author Commented:
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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now