Java App Engine标准环境服务器缓存静态资源

时间:2017-12-13 04:25:49

标签: java eclipse google-app-engine

我使用Java应用引擎组件从Google App Engine插件切换到Google Cloud SDK插件。

现在,当我从Eclipse运行服务器时,它会将我的Web应用程序的所有文件复制到.metadata.plugins \ org.eclipse.wst.server.core \ tmp1

中的临时目录中。

当我修改文件系统上的JS文件时,它们不会自动发布到temp1文件夹,因此当我刷新浏览器时,它会加载旧版本的JS文件。

使用旧的Google App Engine插件,我会修改一个JS文件并刷新浏览器,它会立即加载更改。

我需要修改一些设置才能让它按照我想要的方式工作吗?

我在localhost.server的workspace / Server / App Engine Standard中找到了一个文件。但我不确定自动发布设置的含义。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<server auto-publish-setting="2" auto-publish-time="0" hostname="localhost" id="App Engine Standard at localhost" name="App Engine Standard at localhost" runtime-id="App Engine Standard Runtime" server-type="com.google.cloud.tools.eclipse.appengine.standard.server" server-type-id="com.google.cloud.tools.eclipse.appengine.standard.server" start-timeout="240" stop-timeout="240" timestamp="12">
  <list key="app-engine-server-modules-list" value0="org.eclipse.jst.jee.server:CodeAvengers"/>
  <list key="modules" value0="CodeAvengers::org.eclipse.jst.jee.server:CodeAvengers::jst.web::3.1"/>
</server>

以下是appengine-web.xml

中静态文件的设置
<static-files>
    <include path="/js/**" expiration="1s" />
    <include path="/i/**" expiration="1s" />
    <include path="/audio/**" expiration="1s" />
    <include path="/image/**" expiration="1s" />
    <include path="/images/**" expiration="1s" />
    <include path="/css/**" expiration="1s" />
    <include path="**.nocache.*" expiration="1s"/>
    <include path="/d-md/**" expiration="1s" />
    <include path="**" expiration="30d"/>

    <exclude path="/d/**" />
    <exclude path="/ca/**" />
    <exclude path="/files/**" />
</static-files>

使用旧的Google App Engine eclipse插件,这些设置完全正常。

我检查了temp1文件夹,似乎自动重新发布不起作用。当我修改源文件夹中的文件时,这些更改不会自动发布。

其他地方是否有某些设置覆盖了自动发布设置?

1 个答案:

答案 0 :(得分:1)

auto-publish-setting =“2”是您在右键单击服务器并选择“打开”时修改的Eclipse设置。转到右侧的“发布”类别。有三个选项,每个选项对应一个数字。数字2对应于“资源更改时自动发布”。见下图:

enter image description here

如果要查看静态文件中的更改,则应在appengine-web.xml中为该文件设置低过期属性。它会是这样的:

<static-files>
  <include path="/**.png" expiration="4d 5h" />
</static-files>

在上面的示例中,您可以使用s秒。有关配置选项的列表,请参阅appengine-web.xml reference,尤其是<static-files>static cache expiration部分。

另一方面,如果使用高过期属性,则不会立即看到更改。正如this section所解释的那样:

“..在给定的到期时间内传输文件后,即使用户清除了自己的浏览器缓存,通常也无法将其从中间缓存中清除。重新部署新版本的应用程序将没有重置任何缓存......“