473,414 Members | 1,618 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Web - Images From A Database

Currently, when I want to display an image from a database in my
website, I reference another page with a query string argument of that
image's unique ID in the table. Then that other page grabs the image
and the content type from the database and writes it out to the client.

However, this model seems to be a bit heavy on database overhead when
dealing with a page with many such images. For example, a page which
lists all users on a website and displays the avatar for each user.

I've been trying to come up with a different way to display the images,
but haven't been able to think of anything. The only idea I had was to
grab the content type and image data when populating that datalist of
users and pass them as arguments somehow to that image-outputting page
so it doesn't have to hit the database. If this sounds reasonable, what
would be a good way to do it? I would think the query string would be
unable to handle arguments like that.

Any other ideas on what to do here? Anybody have this problem before
and come up with some other way to streamline the data access?
Regards,
David P. Donahue
dd******@ccs.neu.edu
http://www.cyber0ne.com
Dec 8 '05 #1
5 1286
David,

This sounds like a perfect use for the System.Web.Caching namespace.

Basically, I would store items in the Cache exposed through the Page
that you are running. You can load your Image object instances into it that
represent the images to draw. Then, on your page, you check the cache. If
the item in the cache is there (keyed on whatever input parameters you
need), then you use that image. Otherwise, you can fetch it from the
database.

To make it even faster, I would store the images on disk, instead of the
database. I would name them according to a scheme you come up with
yourself, and store them all in one directory. This will reduce your
overhead by a bit, I believe, since you are not doing all of these database
hits.

You could even tie the item in the cache to a dependency in the file.
Basically, if the file changes, the item in the cache is invalidated, which
requires you to then get the image again and place it in the cache.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"David P. Donahue" <dd******@ccs.neu.edu> wrote in message
news:ug**************@TK2MSFTNGP11.phx.gbl...
Currently, when I want to display an image from a database in my website,
I reference another page with a query string argument of that image's
unique ID in the table. Then that other page grabs the image and the
content type from the database and writes it out to the client.

However, this model seems to be a bit heavy on database overhead when
dealing with a page with many such images. For example, a page which
lists all users on a website and displays the avatar for each user.

I've been trying to come up with a different way to display the images,
but haven't been able to think of anything. The only idea I had was to
grab the content type and image data when populating that datalist of
users and pass them as arguments somehow to that image-outputting page so
it doesn't have to hit the database. If this sounds reasonable, what
would be a good way to do it? I would think the query string would be
unable to handle arguments like that.

Any other ideas on what to do here? Anybody have this problem before and
come up with some other way to streamline the data access?
Regards,
David P. Donahue
dd******@ccs.neu.edu
http://www.cyber0ne.com

Dec 8 '05 #2
> Basically, I would store items in the Cache exposed through the Page
that you are running. You can load your Image object instances into it that
represent the images to draw. Then, on your page, you check the cache. If
the item in the cache is there (keyed on whatever input parameters you
need), then you use that image. Otherwise, you can fetch it from the
database.
I'll have to look into that one, I've never used the .NET Cache before.
Basically, am I right in thinking that, at application startup, I
would fetch the images from the database and store them in active memory
for various user sessions to access?
To make it even faster, I would store the images on disk, instead of the
database. I would name them according to a scheme you come up with
yourself, and store them all in one directory. This will reduce your
overhead by a bit, I believe, since you are not doing all of these database
hits.


I've thought about storing them on the filesystem, but I'd prefer not to
open any kind of write access to the filesystem itself. Not so much for
the security problems that I can think of, but for the ones I can't
think of.

Regards,
David P. Donahue
dd******@ccs.neu.edu
http://www.cyber0ne.com
Dec 8 '05 #3
David,

See inline:
I'll have to look into that one, I've never used the .NET Cache before.
Basically, am I right in thinking that, at application startup, I would
fetch the images from the database and store them in active memory for
various user sessions to access?
Yes, that's the basic idea.
I've thought about storing them on the filesystem, but I'd prefer not to
open any kind of write access to the filesystem itself. Not so much for
the security problems that I can think of, but for the ones I can't think
of.
If that is the case, then this is fine. If you don't have control over
the box, it's another issue as well. If you do, I think that you should
consider it.

However, see how your app performs using the cache. Also, there is a
way to indicate that you want the item in the cache to be dependent on a
column in a table in sql server. If the cache receives notification that
the column has changed, then it will invalidate the cache. This can be
pretty helpful for what you are doing.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

Regards,
David P. Donahue
dd******@ccs.neu.edu
http://www.cyber0ne.com

Dec 8 '05 #4
> If that is the case, then this is fine. If you don't have control over
the box, it's another issue as well. If you do, I think that you should
consider it.
If caching turns out to be more complicated than I want, or has some
other drawback that doesn't fit my needs, then I may end up implementing
some filesystem access. Since it may be the only option left.
However, see how your app performs using the cache. Also, there is a
way to indicate that you want the item in the cache to be dependent on a
column in a table in sql server. If the cache receives notification that
the column has changed, then it will invalidate the cache. This can be
pretty helpful for what you are doing.


A lot of these images rarely, if ever, change. One thing I won't want,
though, is to have a cache outlive a change in any way. I doubt users
would appreciate it if they update something and can't see their changes
right away.

I'm finding a number of articles and tutorials on the subject. Do you
recommend any? I don't need any extra bells and whistles, just caching
images from the database on the application level and keeping the cache
updated when the table(s) get updated.

Regards,
David P. Donahue
dd******@ccs.neu.edu
http://www.cyber0ne.com
Dec 8 '05 #5
David,

Check out the documentation for the SqlCacheDependency class, as well as
the Cache class. Those two areas in the documentation should give you a
good starting point for what you are trying to do.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"David P. Donahue" <dd******@ccs.neu.edu> wrote in message
news:OQ**************@tk2msftngp13.phx.gbl...
If that is the case, then this is fine. If you don't have control
over the box, it's another issue as well. If you do, I think that you
should consider it.


If caching turns out to be more complicated than I want, or has some other
drawback that doesn't fit my needs, then I may end up implementing some
filesystem access. Since it may be the only option left.
However, see how your app performs using the cache. Also, there is a
way to indicate that you want the item in the cache to be dependent on a
column in a table in sql server. If the cache receives notification that
the column has changed, then it will invalidate the cache. This can be
pretty helpful for what you are doing.


A lot of these images rarely, if ever, change. One thing I won't want,
though, is to have a cache outlive a change in any way. I doubt users
would appreciate it if they update something and can't see their changes
right away.

I'm finding a number of articles and tutorials on the subject. Do you
recommend any? I don't need any extra bells and whistles, just caching
images from the database on the application level and keeping the cache
updated when the table(s) get updated.

Regards,
David P. Donahue
dd******@ccs.neu.edu
http://www.cyber0ne.com

Dec 8 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: yawnmoth | last post by:
i have a script that accesses images on a fairly frequent basis, however, i'm thinking that it would be better to have them in an sql database, instead, for the same reason that it is generally...
3
by: Srdjan Pejic | last post by:
Hello, I have a problem that I have not been able to solve, even after searching the web. I have stored couple of images in the MySQL database and I am trying to get them displayed on a web page...
6
by: bissatch | last post by:
Hi, I am currently writing a news admin system. I would like to add the ability to add images to each article. What I have always done in the past is uploaded (using a form) the image to a...
3
by: Alan | last post by:
Hi, I'm converting a database application from Access 97 to C#/SQL Server. Old database contains some images in OLE fields. I've figured out that there's OLE header preceeding actual image data...
10
by: Neo Geshel | last post by:
I am seeking to hand-roll my own blog in ASP.NET 2.0 and SQLExpress 2005. Why? Because I can. Because I will gain experience. The one thing that has me stumped at square one is inline images....
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
10
by: eholz1 | last post by:
Hello Members, I am setting up a photo website. I have decided to use PHP and MySQL. I can load jpeg files into the table (medium blob, or even longtext) and get the image(s) to display without...
3
by: najimou | last post by:
Hi everyone I will be having a split database, running on 2 computers via mapped drive. computer "A" will have one front end and the back end located in c: \mydatabse 2 tables have links to...
1
by: ttamilvanan81 | last post by:
Hai everyone, I need to provide the slideshow for the images. I have upload the images into database. Then i will retrive all the images from the database and provide the slideshow for those...
7
by: Keith Hughitt | last post by:
Hi all, I am having trouble preloading images in a javascript application, and was wondering if anyone had any suggestions. Basically I have a bunch of images stored in a database as BLOBs. At...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.