By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,969 Members | 1,522 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,969 IT Pros & Developers. It's quick & easy.

Can I cache a DataTable in a Session object?

P: n/a
Can I cache a DataTable (or alternative GridView Datasource) in a
Session object?

.... and does the following scenario present itself as an occaison when
I could get away with doing so?

In an Asp.Net 2.0 app. I have a search results page. The results are
diplayed in a GridView with paging and sorting. In would prefer to get
all the data and do the paging/sorting in memory rather than adding to
the complexity of the T-SQL. It's not so much the paging that bothers
me as the sorting (that would be awful - I'd have to put the raw
results in a table variable first, then query the table variable to
get the paged/sorted results).

On any one day there are only about 100 clients who would use this web-
site (not concurrently). The site shares a server with an even less
busy site.

Q1: Am I right in thinking that this data should not be cached in the
Data Cache because each client will have entirely different search
results. (For instance, if two clients use the search page at the same
time that will lead to inconsistenty. - as the second client's data is
cached in the same Cache object as the first.)

Q2: Will it be possible to cache the DataSource for the GridView as
Session object instead? (assuming the above problems with the Data
Cache)

Q3: If I cache in the Session, apart from destroying the session
object (i.e the cached data) on leaving the page - are there any other
major considerations?

Q4: Would the DataSource need to be serializable for it to be storeded
as a session object?.

Jun 7 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Jun 7, 2:08 pm, mark4asp <mark4...@gmail.comwrote:
Q1: Am I right in thinking that this data should not be cached in the
Data Cache because each client will have entirely different search
results. (For instance, if two clients use the search page at the same
time that will lead to inconsistenty. - as the second client's data is
cached in the same Cache object as the first.)
Yes, Cache is available to all users

Q2: Will it be possible to cache the DataSource for the GridView as
Session object instead? (assuming the above problems with the Data
Cache)
Yes

Q3: If I cache in the Session, apart from destroying the session
object (i.e the cached data) on leaving the page - are there any other
major considerations?
Session lives until the time specified for the session timeout

>
Q4: Would the DataSource need to be serializable for it to be storeded
as a session object?.
Not for in-proc sessions

Jun 7 '07 #2

P: n/a
On 7 Jun, 14:07, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On Jun 7, 2:08 pm, mark4asp <mark4...@gmail.comwrote:
Q3: If I cache in the Session, apart from destroying the session
object (i.e the cached data) on leaving the page - are there any other
major considerations?

Session lives until the time specified for the session timeout
Thanks Alexey, the individual Session objects can be removed with
Session.Remove("TheName"). Furthermore I can write a class to run on
every page which overrides OnInit() to check that these session
objects have been killed when the user is no longer on that
appropriate page.

Jun 7 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.