views:

113

answers:

2

I have an existing database containing some pictures in blob fields. For a web application I have to display them.

What's the best way to do that, considering stress on the server and maintenance and coding efforts.

I can think of the following:

  • "Cache" the blobs to external files and send the files to the browser.
  • Read them from directly the database every time it's requested.

Some additionals facts:

  • I cannot change the database and get rid of the blobs alltogether and only save file references in the database (Like in the good ol' Access days), because the database is used by another application which actually requires the blobs.
  • The images change rarely, i.e. if an image is in the database it mostly stays that way forever.
  • There'll be many read accesses to the pictures, 10-100 pictures per view will be displayed. (Depending on the user's settings)
  • The pictures are relativly small, < 500 KB
+1  A: 

I would suggest a combination of the two ideas of yours: The first time the item is requested read it from the database. But afterwards make sure they are cached by something like Squid so you don't have to retrieve the every time they are requested.

Benedikt Eger
+1  A: 

one improtant thing is to use proper HTTP cache control ... that is, setting expiration dates properly, responding to HEAD requests correctly (not all plattforms/webservers allow that) ...

caching thos blobs to the file system makes sense to me ... even more so, if the DB is running on another server ... but even if not, i think a simple file access is a lot cheaper, than piping the data through a local socket ... if you did cache the DB to the file system, you could most probably configure any webserver to do a good cache control for you ... if it's not the case already, you should maybe request, that there is a field to indicate the last update of the image, to make your cache more efficient ...

back2dos