Data stored in the cache is shared; it is not thread-safe. If you modify the data then the next request will see your changes. Sometimes developers are under the illusion that because they have assigned the data in the cache to a new object variable or performed a shallow copy of the cached data that they can make change without consequence. Not true. Here are a few classes to help protect you. However, you still need to ensure that your cacheable objects are deep copied (derive from my IDeepCopy and implement).
Combine this code for request-safe data caching.
The contents of CacheArgs.csThe contents of IDeepCopy.csThe contents of Cacher.cs
Hello. I'm Mark Graham. In no particular order, I love creativity, fine-art/ graphics/ photography, innovativeness, my partner, my kids, guitar music, Joe Satriani(no, not in that way), .net, programming, the web, golf, coffee in, coffee out, my blog, my ambition
Code and Rock is a new methodology that I designed. You basically start up Visual Studio, then slap on a rocking track. Snare that spacebar! Try it with this one from Joe Satriani...
0 comments:
Post a Comment