Accessing ASP.NET Cache from multiple threads
From: Michael Vanhoutte (MichaelVanhoutte_at_discussions.microsoft.com)
Date: 08/21/04
- Next message: Michael Vanhoutte: "RE: Accessing ASP.NET Cache from multiple threads"
- Previous message: Evertjan.: "Re: Strip unknown range of characters between first "/" and second "/""
- Next in thread: Michael Vanhoutte: "RE: Accessing ASP.NET Cache from multiple threads"
- Reply: Michael Vanhoutte: "RE: Accessing ASP.NET Cache from multiple threads"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 21 Aug 2004 02:51:01 -0700
I was wondering how multiple threads can access the ASP.NET cache object
safely. Take for example the following code that I got from the ASP.NET Cache
object documentation:
DataView Source = (DataView)Cache["MyData1"];
if (Source == null) {
// Connecting to a database...
// Filling a dataset...
Source = new DataView(ds.Tables["Authors"]);
Cache["MyData1"] = Source;
}
MyDataGrid.DataSource=Source;
MyDataGrid.DataBind();
The following questions come to my mind:
1. What happens if two threads reach the 'if (source == null)'-line
simultaneously.
They could both start refilling the cache. Do I need to use locks or mutexes
myself if I want to prevent that?
2. Suppose that thread 1 executed the 'if (source2 == null)' line and found
that that source2 wasn't null. What if thread 2 executed
'Cache.Remove("MyData1")' after thread 1 performed that test but before it
had to change to actually use the value in MyData1.
I would grealy appreciate any feedback!
Michael
- Next message: Michael Vanhoutte: "RE: Accessing ASP.NET Cache from multiple threads"
- Previous message: Evertjan.: "Re: Strip unknown range of characters between first "/" and second "/""
- Next in thread: Michael Vanhoutte: "RE: Accessing ASP.NET Cache from multiple threads"
- Reply: Michael Vanhoutte: "RE: Accessing ASP.NET Cache from multiple threads"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|