?
Solved

asp.net suggestions for session vs. database

Posted on 2014-07-17
5
Medium Priority
?
347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1800 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 200 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

752 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