启用指定修改日期的图像缓存 [英] enable caching of images specifying a modified date

查看:114
本文介绍了启用指定修改日期的图像缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个加载很多图像的jsp页面。我想缓存图像以加快加载速度。

I've a jsp page which loads many images. I'd like to cache the images for faster loading.

我会解释我的想法,如果错误请更正。我正在为每个图像调用图片加载servlet并返回BLOB。我的想法是添加一个修改日期与图像和其他值,如Last-Modified,expires,Cache-control和max age。从而使浏览器了解图像是否发生变化。

I'll explain my idea, please correct it if it's wrong. I'm calling the picture loading servlet for each image and return as a BLOB. My idea is to add a modified date with the image and the other values like Last-Modified, expires, Cache-control and max age. And thereby make the browser understand if the image changes.

但是如何将修改后的日期附加到BLOB?还是有一些更好的想法让它们可以缓存?

But how can i append a modified date to a BLOB? Or is there some better ideas to make them cachable?

谢谢......

推荐答案


我有一个加载很多图像的jsp页面。我想缓存图像以加快加载速度。

这是一件好事 TM


我会解释我的想法,如果错误请更正。我正在为每个图像调用图片加载servlet并返回BLOB。我的想法是添加一个修改日期与图像和其他值,如Last-Modified,expires,Cache-control和max age。从而使浏览器了解图像是否发生变化。

为此您实际需要 ETag ,< a href =http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.29 =nofollow noreferrer> Last-Modified 并且还可以选择 过期 标题。使用 ETag 标头,服务器和客户端都可以识别唯一文件。如有必要,您可以在每个数据库密钥下使用它。使用 Last-Modified 标头,服务器和客户端都知道它们是否都具有相同版本的文件。使用 Expires 标头,您可以指示客户端何时在第一个下一个时间重新请求文件(因此,当 Expires中指定的日期已过期。

For that you actually need the ETag, Last-Modified and optionally also Expires header. With the ETag header both the server and client can identify the unique file. You can if necessary use under each the database key for this. With the Last-Modified header header both the server and client knows if they both have the same version of the file. With the Expires header you can instruct the client when to re-request the file the firstnext time (thus, when the date as specified in Expires has been expired).

Cache-Control 标题在这里与您不太相关只是想允许缓存,普通客户端默认已经这样做了。

The Cache-Control header is not so relevant here as you just want to allow caching and the average client already does that by default.

有关更多信息和servlet示例,您可能会发现这篇文章很有用,也可能本文了解您对调整JSP性能感兴趣的案例/ Servlet webapplication。

For more information and a servlet example, you may find this article useful and maybe also this article for the case you'd be interested in tuning performance of a JSP/Servlet webapplication.


但是如何将修改日期附加到BLOB?或者是否有一些更好的想法让它们可以缓存?

只需在有问题的数据库表中添加一列代表插入日期。在大多数数据库中,您只需使用 now()函数,或者甚至将其创建为自动触发器,以便在每次插入/更新时自动设置。

Just add one more column to the database table in question which represents the insertion date. In most DB's you can just use now() function for this or even create it as an auto-trigger so that it get set automatically on every insert/update.

这篇关于启用指定修改日期的图像缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆