如何使用Java在GAE中设置网页缓存设置?
问题描述:
我一直在试图弄清楚我可以在我的网站上为我的网站设置缓存设置,但我无法在其文档中找到相关信息,Google也没有产生任何结果。我读了很多关于缓存的内容,但是我发现的所有结果或代码示例都使用Apache。如何使用Java在GAE中设置网页缓存设置?
任何文档链接?或者只是我实际写入缓存设置的一般信息?也许在某处appengine-web.xml
?
谢谢。任何信息/文档都将不胜感激。
编辑:我已经试过这样的事情在appengine-web.xml
,但它似乎是真的缓存什么都不当我和Chrome浏览器开发工具测试 -
<static-files>
<include path="/**.png" expiration="7d" />
<include path="/**.jpg" expiration="7d" />
<include path="/**.ico" expiration="7d" />
<include path="/**.js" expiration="7d" />
<include path="/**.svg" expiration="7d" />
<include path="/**.ttf" expiration="7d" />
<include path="/**.woff" expiration="7d" />
<include path="/**.css" />
</static-files>
而且只要我添加单静态文件是这样的:
<static-files>
<include path="/img/top_img.jpg" expiration="4d 5h" />
</static-files>
我得到一吨的错误说我需要在我的静态文件列表一切,像这样的 - WARNING: Can not serve /paypal_button.svg directly. You need to include it in <static-files> in your appengine-web.xml.
编辑:这里是卷曲-v日志 -
< HTTP/1.1 200 OK
< Content-Length: 61009
< Content-Type: text/html
< Last-Modified: Wed, 13 Jan 2016 06:19:21 GMT
< Cache-Control: public, max-age=600
< Server: Development/1.0
< Date: Wed, 13 Jan 2016 07:33:39 GMT
所以启用缓存..但我想不出如何如何改变使用GAE单个静态文件到期日期。
编辑:当我测试棒的服务器上使用此代码:我的资源负载的
<static-files>
<include path="/**.png" expiration="999d" />
</static-files>
无,我得到这些错误:
Failed to load resource: the server responded with a status of 404 (Not Found)
上的一切,是不是.png
答
好吧,经过很多烦恼后,我才得以正常工作。基本上与appengine-web.xml
一旦你列出一个事情作为<static-file>
你必须列出每文件类型,你有否则它不会知道它是否是静态的。所以我能够做到这一点 -
<static-files>
<include path="/**.png" expiration="365d" />
<include path="/**.svg" expiration="365d" />
<include path="/**.jpg" expiration="365d" />
<include path="/**.zip" expiration="365d" />
<include path="/**.pdf" expiration="365d" />
<include path="/**.hex" expiration="365d" />
<include path="/**.js" expiration="365d" />
<include path="/**.js.map" expiration="365d" />
<include path="/**.ttf" expiration="365d" />
<include path="/**.gif" expiration="365d" />
<include path="/**.woff" expiration="365d" />
<include path="/**.css" expiration="365d" />
<include path="/**.html" expiration="1d"/>
</static-files>
现在所有的http标题看起来都是正确的。请确保在您的网站上每包含文件类型/文件,否则它将不会加载该资源。
干杯。
你在这里缓存是什么意思? –
很抱歉,如果不清楚,我有一个网站托管在GAE上,我需要为静态文件设置我的缓存设置(当它们到期时设置等) – shanling
这样? https://cloud.google.com/appengine/docs/java/config/appconfig#Java_appengine_web_xml_Static_cache_expiration –