【问题标题】:Java App Engine Standard Environment server caching static resourcesJava App Engine 标准环境服务器缓存静态资源
【发布时间】:2018-05-26 21:30:54
【问题描述】:

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

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

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

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

我需要修改一些设置以使其按我想要的方式工作吗?

我在 localhost.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 文件夹,似乎自动重新发布不起作用。当我修改源文件夹中的文件时,这些更改不会自动发布。

是否有其他设置覆盖了自动发布设置?

【问题讨论】:

    标签: java eclipse google-app-engine


    【解决方案1】:

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

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

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

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

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

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

    【讨论】:

    • 我更新了我的问题,以显示我在 app-engine.xml 中的静态文件设置。这些设置适用于旧的“Google App Engine”插件。
    • 现在情况如何? Eclipse settitng + expire 属性的组合是否有效?
    • 感谢您的回复!!这两套我都已经有了。我刚刚更新了我的答案。问题似乎是自动发布不起作用。我假设它应该将更改从我的源文件夹复制到 temp1 目录中。当我刷新浏览器时,会从 temp1 文件夹加载版本。在一次阶段,我确实看到了一条关于难以复制到 temp1 文件夹的错误消息。我将尝试在管理员模式下重新启动 Eclipse,看看是否可以修复自动发布。
    • Window > Preferences > Server > Launching 中尝试this doc
    • 我试过了……还是不行。当我重新启动服务器时,所有更改都会从源目录复制/发布到临时目录中。但是服务器运行后所做的任何更改都不会自动发布。
    猜你喜欢
    • 2018-03-29
    • 1970-01-01
    • 2018-03-12
    • 2018-07-01
    • 1970-01-01
    • 2018-10-07
    • 2020-11-23
    • 1970-01-01
    • 2019-01-30
    相关资源
    最近更新 更多