views:

160

answers:

2

Here's my scenario: 1) User runs search to retrieve values for display in ListView via LinqDataSource. 2) They click on one of the items which takes them to another page where the details can be examined, further drill-down can happen, etc. 3) User wants to go back to the original ListView results to select another item for inspection.

I can see it's possible to pass the querystring params around, allowing the querying to be duplicated each time the user comes back to the ListView, but it seems like there ought to be a way to cache the results.

Since I'm using the LinqDataSource, though, I believe the actual results are fetched each time the query is run. I'm currently feeding a "select new {blah, blah}" type of IEnumerable to the e.Results, which can't be turned into a List since it's populated with anonymous types.

In short: 1) Does it make sense to try to place potentially large query results in the users session? 2) If it does, is a List the reasonable data structure? 3) Do I need to resort to something like creating a class with the correct properties to hold the anonymous data, enumerate the query return, populate the List? 4) Is there a better option than the LinqDataSource for this type goal? 5) Or, does it just make more sense to run the query each time they hit the ListView?

I apologize if this wasn't clear. I would really appreciate it if someone can set me straight before I nuke a bunch of my free time headed down the wrong path :)

+2  A: 

First, I would suggest that you look into the caching mechanism that comes with ASP.NET, unless the data is private for a certain user.

Second, I would suggest that you design your application in a way so that you create natural points where you could try to get data from a cache before querying the database (and insert data into the cache, with expiration rules), but don't start putting stuff into the cache until you have verified that it will actually make a difference.

Measure how much time that is actually spent on retrieving data and use caching in the cases where it makes a difference.

Fredrik Mörk
+1, though I'd reverse the two points. :) Definitely run the query each time they hit the list view, until it's proven to be a problem. A modern RDBMS can handle way more than many people give them credit for, and often provide a caching layer of their own!
Jeff Sternal
A: 

I'm not sure if resurrecting threads from the dead is cool on SO, but here is what I found to answer this question:

http://weblogs.asp.net/pwelter34/archive/2007/08.aspx

jeffesp