• Efficient, Thread-Safe Caching with ASP.NET

    Published on FEB 27, 2012 about a 3 minute read

    Let me start by saying that I’ve made this mistake on many occasions in the past. I just assume that static/shared objects are thread-safe. Things like HttpContext.Current.Cache…OOPS! A typical implementation of a cache lookup might look like this: Let’s analyze this code in a little detail. Here are the steps performed: Load the object from the Cache If the object is null (not found) Create the object and store it in the cache Return the object back to the caller To start, we should ask, what happens if 10 simultaneous requests come through attempting to get to the cache object?

    .NET, CACHING, THREADING

home


Copyright © 2018 pseudomuto.com. All rights reserved.