locked
Cleaning up session data in AppFabric Cache RRS feed

  • Question

  • Hello, 

    I'm using AppFabric Cache as my Session provider in my Web Role. At the moment my application is under test by only a few users (totally 3) but I noticed the size of cache is 15 MB! I'm not storing big objects in the Session and am surprised why this is the case. I'm concerned if my application is deployed to production, I'll need Gigs of cache! So something is wrong here... 

    To give you an overview of how I use Session: I have a page that queries the database and applies some randomization to the results returned. Then it stores a List of DTOs for the user in his Session. These DTOs are simple objects without any hierarchy and include only a few properties. I don't think the size of each DTO would be more than 200 bytes. At present, there could be 5 DTOs in the list. So, the total amount of Session memory used by each user shouldn't exceed a few KBs in the worst case scenario. 

     

    The only thing that I think is causing this problem is that everytime the user gets back to this page, a new list is generated and stored in the Session. I'm thinking perhaps the old list that was in the Session is still there and is not garbage collected. Do you think this is the reason? If yes, how should I clean up the old list prior to assigning a new list to Session? This is what the code looks like:

    Session["List"] = GetListFromServiceLayer();

     

     

    Cheers,

    Mosh

     

     

     

    Thursday, November 24, 2011 2:52 AM

All replies

  • Hi,

    Base on my understanding, if you think the problem is old session data not being removed, try to call Session.Remove to manually remove it.

     

    Best Regards,

    Ming Xu.


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    Thursday, November 24, 2011 2:45 PM
  • Yeah I haven't tested this yet but I did some calculations and I think this is the cause of the problem. So everytime the user visits that page, a new list is generated and inserted into the Session with the SAME key. I think the reference to the old list in Session is lost but the list object is actually in the memory. So perhaps I should remove it first before assigning a new list to the Session. 

     

    In the meantime, is there a way to clean up all the data in AppFabric Cache? I'm talking about those object instances that I have lost references to. 

    Thursday, November 24, 2011 9:27 PM
  • I already tried removing the old list from Session while assigning a new list just in case garbage collector could not clean up the Session. But the problem still exists!! My Cache usage keeps increasing... 

     

    Are there any ways to inspect what is stored in the cache?

     

    How can I troubleshoot/monitor cache issues?

    Friday, December 2, 2011 1:17 AM
  • Hi,

    The issue that you mentioned can not be reproduced at my side, I would recommend you to use Windows Live SkyDrive to share the sample project. You can remove any confidential information or business logic from it. Then we can find the issue more conveniently and provide further suggestions for you.

     

    Best Regards,

    Ming Xu.


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    Sunday, December 4, 2011 3:22 PM
  • Hey Ming, Thank you for your message. Unfortunately, due to the complexity and confidentiality of the project, I cannot upload it to SkyDrive. There are so many moving parts and setting it up on your machine would be a headache. In the meantime, is there any way for me to inspect the cache? I'm wondering what is stored there and why it keeps increasing!! Now 50MB is used and there are totally 2-3 users using my application!!

     

    Wednesday, December 7, 2011 10:18 AM