cache Dataset

A

Arthur Dzhelali

Is there any way to cache dataset on one page and it will be accessible for
one user?

if you declare dataset shared it will stay on the server and page will be
able reference to it on reload, but in this case it will be shared with
other users who use the page.
Right now I found work around it by saving each dataset as xml file with
users's sessionid in file name and reading it on page reload.

is there a better way?
 
C

Claudio

why not cache it in a session variable?

Session.Contents["CachedDataSet"] = new DataSet();
 
A

Arthur Dzhelali

I was trying to avoid session

why not cache it in a session variable?

Session.Contents["CachedDataSet"] = new DataSet();


Arthur Dzhelali said:
Is there any way to cache dataset on one page and it will be
accessible for
one user?

if you declare dataset shared it will stay on the server and page
will be able reference to it on reload, but in this case it will be
shared with other users who use the page.
Right now I found work around it by saving each dataset as xml file
with users's sessionid in file name and reading it on page reload.

is there a better way?
 
K

Kevin Spencer

Making anything Shared is something you should avoid unless it NEEDs to be
Shared, as Shared classes remain in memory for the lifetime of the
application. When talking about caching, it's best to think in terms of
scope. What is the desired scope of the object? Is it supposed to be
available to only one Page, one User, all Pages of one User, all Users?
There are different types of cache for different scopes and situations. You
stated that you want to cache it on one page. There is a cache that is
available at Page scope, and that is ViewState. Forgive me if I review
anything you already know here.

ViewState is a Collection on the server side, but on the client it is a
hidden form field. In other words, when you store something in the Page
ViewState, it is stored as text in the WebForm on the client (in the
browser). Because of this, objects stored in ViewState must be serializable
(able to be translated into text). Fortunately, a DataSet is serializable,
and you can safely store it in ViewState. The down side to using ViewState
is the amount of data that you store there. Since ViewState is stored in a
hidden form field on the client, the data must be sent to the browser with
the HTML response. If there is a lot of data, it may take awhile for the
page to load on the client, and awhile to pass back to the server (the data
is in a hidden form field, so it gets posted back to the server).

You also have the option of storing it in Session, as has been suggested.
Apparently, you don't want to use Session State, although this is a
perfectly good place to cache data that is global to all pages of a single
User Session. The only things you have to be careful about when using
Session State are (1) Making sure that you handle Session Timeouts, and (2)
being careful not to load too much into User Sessions, as there will be that
amount of memory allocated to each User Session.

There are other caching mechanisms available, but for the scope which you're
describing, I would think wither ViewState or Session State would be your
best bets.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

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

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top