Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7563453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:40:13+00:00 2026-05-30T13:40:13+00:00

Background: I’m writing ASP.NET MVC 3 Web app. I have a List<MyObject> (actually several

  • 0

Background: I’m writing ASP.NET MVC 3 Web app. I have a List<MyObject> (actually several lists) of objects I want to keep in cache due to handy automatic expiration feature and thread-safety.

Each of those objects internally contains instance of System.Threading.Semaphore used for internal Server push implementation.

So I wonder how will change my objects’ lifecycle if I put them into cache? May this create problems with threading/NullReferenceExceptions if cache actually disposes objects it purges/etc.? Maybe some other obvious reasons not to do this?

TIA.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:40:14+00:00Added an answer on May 30, 2026 at 1:40 pm

    The cache doesn’t explicitly dispose objects when they are ejected from the cache for whatever reason. You could prove this by testing it, but if this was the case it would be in the documentation, and it isn’t:

    http://msdn.microsoft.com/en-us/library/system.web.caching.cache.aspx

    The lifecycle of the objects in the cache may be extended by being in the cache, since the cache is holding a reference to them. If you want to avoid this you can instead cache a weak reference.

    http://msdn.microsoft.com/en-us/library/system.weakreference.aspx

    If you do this there should be no lifecycle implications of storing the reference in the cache.

    One thing to think about – you say you want to use the cache because it is thread safe. You should be aware that the cache object itself is thread safe, but if you cache a non-thread safe object in the cache that won’t make the cached object itself automatically thread safe. Specifically List<T> is not thread safe and storing it in the cache won’t change this. Use the concurrent collections if you want to ensure thread safety.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I'm testing a function within an ASP.NET 4.0 (Web Forms not MVC) and
Background: I have a little video playing app with a UI inspired by the
Background I am writing code in VS 2010, .NET 4, C#. Also, in case
Background: I've wrote a small library that is able to create asp.net controls from
Background I am developing a social web app for poets and writers, allowing them
Background: I have some existing apps in the App Store and I have just
Background: I am using Eclipse to develop an Android app. I have an xml
Background Use Ajax to fire an event to the web server when a list
Background: I am writing a flash game and have encountered a problem. I have
Background: I have a Visual Studio solution consisting of a website + REST web-service

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.