1

I have a List of byte array images.

I am showing an image in HTML page. If I want to display 25 such images I have to go 25 times to the database.

I want to avoid that please help.

HTML code

myProfile.init(function (map) {
    dom.byId("Image").src="UserImageDisplay?&userId="+map["userId"];    
}

Java code

byte[] image = userSession.getPhoto(Integer.parseInt(request.getParameter("userId"));

response.setContentType("image/imagetype");

OutputStream out = response.getOutputStream();

out.write(image);
out.flush();
out.close();

2 Answers 2

1

Well You have get the Image from somewhere , be it a DB or a File Server.

Since you have suggested , you dont want to load it every time from DB.

Here's what i would do to improve the performance.

1) Cache your images whenever you fetch one(thats not available in Cache) from the Db. 2)The cache can be Server Memory(highly advice against this , as you can quickly run out of memory) , or cache the images in local storage.

3) Storing of images in the cache , can be done realtime ie when the file is requested from the Web App, or you could schedule a cron/batch job to do that before hand .Preferably during off peak hours.

Choice between3 and 4 depends on how frequent the images are updated in the Database. I will leave it up to you.

4) You can explicitly specify the browser to cache the images.You can accomplish it with tag

Sign up to request clarification or add additional context in comments.

Comments

0

I think you should cache your images.

Best would be you start a cron job that generates image files.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.