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 5 1269
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
> 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
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
> 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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
| |