Cached DataView and Thread safety

G

Gabe Moothart

Hi,
I'm creating a database-driven asp.net application, and I'd like to
improve performance by caching the Data, so I don't need to make as many
trips to the database (this is read-only data, btw. I don't do any
updating).

Basically, I populate a Dataset, and add its DefaultView to the cache if
it isn't already there. Then I apply some customer filtering/sorting,
and display it in a DataList.

I'm worried about the thread-safety of this approach. Specifically,
since there is only one instance of the cached DataView which gets
passed around between session/threads, is it possible for my
RowFilter/Sort settings to get overwritten?

For example:
1) Joe visits my site. He requests to see records with ProductID=1.
2) the DataView is retrieved from the cache, and RowFilter is set to 1.
3) Bob visits my site, and requests to see records with ProductID=2
4) the DataView is retrieved from the cache, and RowFilter is set to 2.
5) The Datalist on Joe's page is bound to the DataView
6) The Datalist on Bob's page is bound to the DataView

Both Joe and Bob see Products with an ID of 2.

Is there a way to prevent this from happening?

thanks,
Gabe
 
J

John Saunders

Gabe Moothart said:
Hi,
I'm creating a database-driven asp.net application, and I'd like to
improve performance by caching the Data, so I don't need to make as many
trips to the database (this is read-only data, btw. I don't do any
updating).

Basically, I populate a Dataset, and add its DefaultView to the cache if
it isn't already there. Then I apply some customer filtering/sorting,
and display it in a DataList.

I'm worried about the thread-safety of this approach. Specifically,
since there is only one instance of the cached DataView which gets
passed around between session/threads, is it possible for my
RowFilter/Sort settings to get overwritten?

Instead of caching the DataView, just cache the DataSet. Let each page which
uses it apply the filtering and sorting with its own DataView.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top