Solved

asp.net suggestions for session vs. database

Posted on 2014-07-17
5
335 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:BobCSD
  • 2
  • 2
5 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
How big are the files?
0
 
LVL 1

Author Comment

by:BobCSD
Comment Utility
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 74

Accepted Solution

by:
käµfm³d   👽 earned 450 total points
Comment Utility
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
Comment Utility
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 1

Author Closing Comment

by:BobCSD
Comment Utility
thanks!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now