【问题标题】:Caching with Play framework and Java使用 Play 框架和 Java 进行缓存
【发布时间】:2014-07-24 02:56:45
【问题描述】:

我正在使用 Play 和 Java 运行应用程序,我需要为各种类型的资产设置到期日期:图像、css、javascript 等。

我在 conf/routes 文件中有以下内容:

GET     /assets/*file               controllers.Assets.at(path="/public", file)

我能够为application.conf 中的一个单独文件设置到期日期:

"assets.cache./public/js/pages/validation.js"="max-age=7200"

但我无法为整个文件夹设置它。我试过了

"assets.cache./public/js/pages/*.js"="max-age=7200"
"assets.cache./public/js/pages/*"="max-age=7200"

但什么也没发生。我希望为 /js/pages 文件夹中的所有内容设置到期日期。

我也试过

assets.defaultCache="max-age=7200"

根据说明 http://www.jamesward.com/2014/04/29/optimizing-static-asset-loading-with-play-framework

还有

http.cacheControl=7200

根据文档http://www.playframework.com/documentation/1.2.3/configuration#http

这些都不起作用。上述更改是在 application.conf 中完成的。

我知道有一种方法可以通过定义控制器来更改我想要为其设置到期日期的路由的 response(): far future Expires header for static contents

但我想知道如何从 application.conf 文件中配置资产的到期日期。

我们的应用程序在 S3 Linux 实例上运行,因此无法在服务器上配置过期日期。

谢谢!

【问题讨论】:

    标签: java playframework playframework-2.0 browser-cache expires-header


    【解决方案1】:

    播放框架不支持"assets.cache./public/js/pages/*.js"="max-age=7200"assets.defaultCache="max-age=7200" 应该可以工作。

    在调试/开发模式下(使用播放运行启动应用程序)assets.defaultCache 被忽略,因此它始终是“无缓存”。确保您在 prod 模式下运行它(使用 play start)。

    我在文档中找不到任何参考,但可以在 https://github.com/playframework/playframework/blob/master/framework/src/play/src/main/scala/play/api/controllers/Assets.scala AssetInfo::cacheControl 函数中查看相同的参考

    【讨论】:

    • 能否请您在回答中参考Play2的具体文档
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-12
    • 2013-09-21
    • 2013-12-14
    • 1970-01-01
    • 1970-01-01
    • 2013-04-03
    • 1970-01-01
    相关资源
    最近更新 更多