Re: Storing images in a db (for web/midlet access)

Поиск
Список
Период
Сортировка
Искать

Re: Storing images in a db (for web/midlet access)

От:
John Sidney-Woollett <johnsw@wardbrook.com>
Дата:
You need to create a servlet (or the equivalent in ASP, PHP etc) that 
sits between the clients browser and your database. In this layer you 
implement a cache. The first time the image is requested you retrieve it 
from the database and serve it normally, but you also copy the byte 
stream to your cache (possibly using the image URL as your cache key).

The next time the image is requested, you check the cache first to see 
if you can serve the image directly from there, otherwise you go back to 
the database again.

If you're using java, looked at implementing a LRU cache using 
LinkedHashMap, and you'll need to read up on HttpResponseWrappers to 
intercept the byte stream and write it to your cache.

Also keep details of the modification date of the image resource, size 
and the "etag". You may find a client making a HEAD request to check 
that the image hasn't changed - serving this data from your cache will 
definitely yield a performance boost as the client won't then need to 
request the image.

Caching is no silver bullet if you're serving hundreds/thousands of 
different images in a short time frame and your cache size is memory 
limited as you may find that you are not be able to hold images in 
memory long enough to make the cache viable.

This is not a postgres issue so much as a web application design issue. 
You may be better off directing your questions to a list more 
appropriate for the web technology you are using.

John

Assad Jarrahian wrote:
> Hi All,
>   So I am trying to store images in the db which will be accessed from
> a midlet and website.
> So I looked into generating temp files, such as the one done here
> using servlets (http://fdegrelle.over-blog.com/categorie-275139.html).
>   What I am confused about is that this may not be very efficient.
> When one browses a website, the pages (and hence the images) are
> basically cached in the browser, but with this method, it seems that
> every access to an image (that has already been viewed in a web
> session) is going to cause a re-query to the database. Not that
> efficient, no?
>    Is there another way around that will help me take advantage of
> caching etc, just like it would with storing images on fs?
>    Much thanks in advance!
> 
> -Assad
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings

Storing images in a db (for web/midlet access)

От:
Assad Jarrahian <jarraa@gmail.com>
Дата:
Hi All,
  So I am trying to store images in the db which will be accessed from
a midlet and website.
So I looked into generating temp files, such as the one done here
using servlets (http://fdegrelle.over-blog.com/categorie-275139.html).
  What I am confused about is that this may not be very efficient.
When one browses a website, the pages (and hence the images) are
basically cached in the browser, but with this method, it seems that
every access to an image (that has already been viewed in a web
session) is going to cause a re-query to the database. Not that
efficient, no?
   Is there another way around that will help me take advantage of
caching etc, just like it would with storing images on fs?
   Much thanks in advance!

-Assad
FAQ