Can I cache a DataTable in a Session object?

M

mark4asp

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?.
 
G

Guest

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
 
M

mark4asp

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.
 

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

Members online

No members online now.

Forum statistics

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

Latest Threads

Top