Tuesday, March 13, 2012

session variables and controls

I'm looking at three options and need advice.
Assuming these pages will have a large amount of users at any time

Option 1:(least server intensive, in my opinion)
Page loads a large TreeView populated from a database SPROC
In each node is a URL link that when clicked opens a new page and populates the information on that page from another SPROC.
Basically the treeview is only loaded once but I'm not thrilled about opening a new window when a node is clicked.

Option 2: Page Loads the TreeView same as above but each node calls the same page with a querystring that loads the new information.
Problem is that all Postbacks and non-postbacks require reloading the TreeView (More hits to the database, unless it retrieves from cache?)

Option 3: Page Loads TreeView same as above but stores the TreeView in a session variable-This works in that after the first hit the TreeView is always repopulated from the session version of the TreeView. (No more hits to the database) Ok...well if each person has a session variable of a TreeView is this a large memory resource? Is a session of a largly populated TreeView extremely more memory intensive than say a session of a string?

What would be considered more resourse intensive, consecutive hits to the database or one large session variable per user hit.

Anyone who can shed some light on this or even offer some alternatives would be great! Thanks.look into viewstate as another option perhaps. Just check MSDN or search on here or google about viewstate
Da bomb. there are a ton of different examples out there: google ajax.

http://webui30.componentart.com/callback/features/ajax_treeViewContent/WebForm1.aspx
ASP.NET caching can allow you to cache the dataset for that treeview control, to which you can bind everytime. If it doesn't exist, then only would you need to retrieve it from the database.
mendhak,
I came up with the idea to store the treeview in a session variable.
The first hit to the database populates the treeview and also gets stored to the session variable. ie: session("mytreeview")
When the page is reloaded it checks the session state and reloads the treeview from the session and not the database. So that solves the database getting hit consecutivly. Is this what you mean by cacheing, if not what technique would you use to accomplish this?
As I understand it viewstate is sent back as a hidden element in the form so in my thinking viewstate probably takes as much resourse as the session version I created, but I don't know for sure. They both could get very large depending on how many nodes your treeview has. Mine is quite large and I'm expecting a large volume of users so my quest is to keep things at a minimum with maximum results. Ideally I should load my treeview in one page and then the nodes would open a new window meaning the treeview would ever get loaded once per page hit, but ideally I want to recall the page from the nodes to populate a multiview, I actually have it all working just really curious as to ideas and best techniques for keeping the load on the server at a minimum. THX, GT
No, what you're doing is actually worse than storing it in ViewState. For each user, a session variable would be created, and so that'd increase server load.

Here, read about .NET Data Caching:

http://aspnet.4guysfromrolla.com/articles/100902-1.aspx
Thanks that worked out nicely. I didn't feel easy with what I came up with which is why I posted the question, I knew that I was creating server load, I just wasn't sure what is considered acceptable usage and would be ok.
The cache being shared by all users makes a great deal more sense and makes me feel alot better about server load and a application that can stand up to heavy usage. Thanks again.

0 comments:

Post a Comment