第二次刷新后,最后修改的标题不起作用

时间:2016-08-18 10:41:37

标签: java spring http-headers last-modified if-modified-since

如果没有更改,我想从缓冲区加载photourl,但只有在第一次刷新页面后才能工作。当我第一次打开页面时,这是我的回复

Cache-Control no-cache
Content-Length 12279
Content-Type text/plain
Date Thu, 18 Aug 2016 10:26:45 GMT
Expires Mon, 01 Jan 1990 00:00:00 GMT
Last-Modified Thu, 18 Aug 2016 09:56:55 GMT
Server Development/1.0
刷新后我有304状态和响应:

Cache-Control no-cache, no-store, max-age=0, must-revalidate
Date Thu, 18 Aug 2016 10:29:21 GMT
Expires 0
Last-Modified Thu, 18 Aug 2016 09:56:55 GMT
Pragma no-cache
Server Development/1.0
X-Frame-Options DENY
X-XSS-Protection 1; mode=block
x-content-type-options nosniff

并在请求中

If-Modified-Since Thu, 18 Aug 2016 09:56:55 GMT

在另一次刷新后,我有200状态,如首次访问,数据从服务器重新加载。

这是我的控制器。

@ResponseBody
@RequestMapping(value = "/photo", produces = "text/plain", method = RequestMethod.GET)
public String myPhoto(HttpServletResponse response, WebRequest request) {

    Photo photo = photoService.getPhoto();

    long lastModified = photo.getModificationDate().getTime();
            if (request.checkNotModified(lastModified)) {
              return null;
            }
            return photo.photoURL();            

}

0 个答案:

没有答案