What is more efficient to send between web pages objects by session or to send ID and make new queries to sql server?
I have a web page where I gather information and create an object and two collections. The details are saved in tables on sql server. This information must be transfered to another web page in order to create a report. What is more efficient to send the object and collections as Session objects or to send only th开发者_JAVA百科e ID (in this case one is enough for all three objects) and then to make three queries to the sql server from the new web page in order to retrieve the information. Thank you, Dov
I would use the Cache for that. If the server is under heavy (memory) stress, the object is disposed and you just rebuild the object. If not, you can reuse it from the cache. And it will be cleaned up automatically if not used for a certain time. And thus it will prevent you from filling up your memory with old session-level objects.
More detailed:
- Put the object in the cache, using the ID
- Pass the ID to the other page
- The other pages, checks the cache, if not found, rebuild/retrieve the object from sql
I think using a Session will be better, specially if querying the db is expensive, such as if if the db on another server or the queries are big and contains a lot of joins for example.
But note that you must the take care from your session variables and clear them if you don't need them, to keep your website server memory fresh.
If your data is not sensitive I would use Session in order to improve performance (you already have the data you need). Otherwise I would pass che id and use the queries.
Using Session will improve performance and reduce load on your server but it can adversely affect your scalability. You can reduce such effect by making such storage as short as possible, usually down to redirects when I am using RPG
.
You need to focus on your bottleneck. What is the problem you are trying to solve? Do you have a database which has reached its resource limit (so use session)? Or you are experiencing a load on the server where Web Server is running out of resources (use requery)?
if you use sessions u will be able to navigate to the next page and generate the report but the information will not be stored for future use.if u want to store the generated report for future use u will need to query the database for the saved repot.so my point is if u will need to query the database once why not save the information first in the database then generate the report accordingly using sql query .
the choice is yours whether u want a temporary report or want to save the information for future
精彩评论