PC Review


Reply
Thread Tools Rate Thread

ASP.NET cache object thread safe?

 
 
=?Utf-8?B?TWFjY2E=?=
Guest
Posts: n/a
 
      6th Sep 2006
Hi

I have a N-tier ASP.NET application that uses a data access tier to get data
from a database and pass it to the middleware/business tier for
processing/filtering and then passes the modified data to the web tier for
presentaion.

What I would like to do is introduce a cache to the middleware tier to cut
down on the round trips to the database.

The question I have is this. Is the cache threadsafe? I will be accessing it
from two different places in the middleware tier. One to read the cache, the
other to update the cache.

Reading newsgroups I am getting conflicting messages as to whether the cache
is thread safe or not.

I'd appreciate any advice,

Thanks
Macca
 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      6th Sep 2006
Macca,

Well, the documentation for the Cache class in the System.Web.Caching
namespace declares that the instance is safe for multi-threading. Of
course, this makes sense, given that it is going to be hit by a number of
threads that are processing page requests.

However, I would recommend that you not use the cache in your
middleware. This ties your middleware to ASP.NET, which in general, isn't a
good idea. It doesn't make your routines portable at all, in case you
decide to access your middleware through other means.

I would recommend taking a look at the enterprise library:

http://msdn.microsoft.com/library/?u...ml/EntLib2.asp

In it, I would take a look at the caching application block, which
actually has more features than ASP.NET's caching mechanism:

http://msdn.microsoft.com/practices/...l/caching1.asp

I would also assume that this is thread safe, but if you don't trust it,
the code for the application block is distributed with the library, so you
can make it thread safe, if you wish or you find that it isn't.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Macca" <(E-Mail Removed)> wrote in message
news:64D1E83F-4A3E-4674-A52F-(E-Mail Removed)...
> Hi
>
> I have a N-tier ASP.NET application that uses a data access tier to get
> data
> from a database and pass it to the middleware/business tier for
> processing/filtering and then passes the modified data to the web tier for
> presentaion.
>
> What I would like to do is introduce a cache to the middleware tier to cut
> down on the round trips to the database.
>
> The question I have is this. Is the cache threadsafe? I will be accessing
> it
> from two different places in the middleware tier. One to read the cache,
> the
> other to update the cache.
>
> Reading newsgroups I am getting conflicting messages as to whether the
> cache
> is thread safe or not.
>
> I'd appreciate any advice,
>
> Thanks
> Macca



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Thread safe cache Andrus Microsoft C# .NET 0 24th Jan 2009 09:06 PM
Are Application collection and Page.Cache thread safe? Max2006 Microsoft ASP .NET 5 22nd Aug 2007 10:54 AM
Implementing thread safe Queue collection object =?Utf-8?B?TWFjY2E=?= Microsoft C# .NET 4 31st Jan 2006 09:58 AM
Thread safe singleton to access the cache? =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?= Microsoft ASP .NET 1 6th Oct 2005 10:49 PM
Is ArrayList in application object are thread safe? =?Utf-8?B?U3RlcGhhbmU=?= Microsoft ASP .NET 5 4th Oct 2005 08:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:28 AM.