love to code .net

blogging mostly about one of my favorite subjects, programming

ASP.NET Concurrency and Cache Access

Concurrency must be considered when writing an ASP.NET application.  Why it must be considered is because page requests are handled concurrently.  I have seen a lot of ASP.NET code that would run fine in a single-thread, but not in a multi-threaded application.  In particular, I've seen this often with code that is accessing the application Cache.  The cache is thread-safe. How you use it, however, is not always.  Here's a example that represents many cases I've seen posted on the web.

More...