1

我有一个字节数组图像列表。

我在 HTML 页面中显示图像。如果我想显示 25 个这样的图像,我必须访问数据库 25 次。

我想避免这种情况,请帮忙。

HTML 代码

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

Java 代码

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

response.setContentType("image/imagetype");

OutputStream out = response.getOutputStream();

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

2 回答 2

1

好吧,您已经从某个地方获得了图像,无论是数据库还是文件服务器。

既然你已经建议了,你不想每次都从数据库加载它。

这是我为提高性能而要做的事情。

1)Cache your images每当您从数据库中获取一个(缓存中不可用的)时。2)The cache can be Server Memory(强烈建议不要这样做,因为你会很快耗尽内存)or cache the images in local storage,。

3) Storing of images in the cache,可以是done realtime当从Web App 请求文件时,或者you could schedule a cron/batch job事先这样做。最好在非高峰时段。

之间的选择3 and 4 depends on how frequent the images are updated in the Database。我会把它留给你。

4)你可以明确地。你可以用标签specify the browser to cache the images来完成它

于 2013-03-08T09:10:01.543 回答
0

我认为你应该缓存你的图像。

最好是您启动一个生成图像文件的 cron 作业。

于 2013-03-08T07:01:48.573 回答