asp.net suggestions for session vs. database

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!
LVL 2
Starr DuskkASP.NET VB.NET DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
How big are the files?
0
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
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
käµfm³d 👽Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CodeCruiserCommented:
Option C would be to store the ID in session and the image file on disk. This would help in caching as well.
0
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.