Solved

asp.net suggestions for session vs. database

Posted on 2014-07-17
5
338 Views
Last Modified: 2014-07-18
I want to know the best performance for this scenario:

I have one page. On that page is the logged in user's client logo.
I could go to the user's client table and retrieve the logo from the database every time I hit the page.
Or I could save in a session the string for the logo when the user logs in.

Which is better on the system:
hitting the database to do this only when on that page.
vs. storing a session that will retain the value when visiting every page on the site, even though only needed on that one page.
or option C?

thanks!
0
Comment
Question by:Starr Duskk
  • 2
  • 2
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40203521
How big are the files?
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 40203633
I wouldn't be storing the file. I'd be storing the ID of the file and hitting the database to retrieve the file, but wouldn't have to hit the database to look up the id for the client. I never thought about storing the file itself in a session.

1. look up employee
2. find their clientID
3. go to the client table
4. find the client setup table
5. look up if they have an image uploaded for the logo
6 get the imageID
7 store the id in a session.
8 when I need to display the logo, use the id and pull it from the image table and display it.

That was my intended plan with the session. As opposed to just taking those 8 steps every single time I hit that page. so I'd just be storing a number in the session, not the image.

should I store the image? It would be a transparent png. can't say how big it would be. might vary.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 450 total points
ID: 40203645
Keep in mind that--assuming you are using "in-proc" sessions--anything you store in Session takes up memory on the server. Whether you store the ID or the image itself, both consume memory, the latter of course taking up more memory. Personally, I'd probably store the ID and then take the hit on the image query.

Another approach you could take is passing the image ID down to the browser--as hidden input or a cookie--and then letting the browser submit the ID on each request. Since this is data sent by a client machine, you may not want to take this approach because you could potentially have end-users fiddling with the IDs to see what other images they could make display. But you could also encrypt the ID before sending it down to the client.

Keep caching in mind as well. Most web servers and web browsers cache image files until they are told that they need to refresh or they have purged their cache. You might be OK eating the initial hit to the database to retrieve the image and then letting cache take over for subsequent displays. You'd want to test this thoroughly, of course.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 50 total points
ID: 40204178
Option C would be to store the ID in session and the image file on disk. This would help in caching as well.
0
 
LVL 2

Author Closing Comment

by:Starr Duskk
ID: 40205579
thanks!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question