473,385 Members | 1,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

ASP.NET cache object thread safe?

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
Sep 6 '06 #1
1 10339
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]
- mv*@spam.guard.caspershouse.com

"Macca" <Ma***@discussions.microsoft.comwrote in message
news:64**********************************@microsof t.com...
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

Sep 6 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Timo | last post by:
I'm trying to make a thread safe object cache without locking. The objects are cached by the id of the data dict given in __new__. Objects are removed from the cache as soon as they are no longer...
5
by: stefano mostarda | last post by:
Hi there, I have a question. In my application I have a table which is frequently used to fill a combo. I want to store it in the application or cache object. it is never updated. What's...
4
by: Mat | last post by:
Hi, I've stumbled onto a problem when using the caching object in ASP.Net. I'm placing a static dataset to the cache as the data only changes once a day. Whilst writing to the cache I'm using...
5
by: eXseraph | last post by:
In application state, we need to use "Application.Lock()" before we write something into Application. My question is do we need use "Application.Lock()" to LOCK the cache before we write into Cache?
1
by: Christopher | last post by:
In one of our ASP.NET Pages, we are starting a new background thread that we do not need to go and get any status on or use after the page finishes. The thread merely does some background stuff on...
1
by: William Sullivan | last post by:
I'm trying to nail down some issues with the cache in my application. Currently, I have an object that stands between my business logic and database logic called CacheLogic (cute, no?). ...
5
by: Joseph Geretz | last post by:
Of course, I can store a C# class instance to the Server Cache (this.Context.Cache). I've tried it. My question is, will this destroy the scalability of my application? My background is VB6....
6
by: O.R.Senthil Kumaran | last post by:
Hi, There is an Open Tracker item against urllib2 library python.org/sf/735515 which states that. urllib / urllib2 should cache the results of 301 (permanent) redirections. This shouldn't break...
5
by: Max2006 | last post by:
Hi, Since Application collection and Page.Cache can be shared among all sessions, I wonder if they are thread safe? Thank you, Max
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.