我有一个Dropwizard网络服务器,其余的api也提供一些静态内容,如html,css,javascript和jpg图像。不幸的是,当我更改html或添加其他图像时,始终需要重新启动服务器才能将更改生效。在Dropwizard中禁用静态资产缓存
正如我认为这可能是一个缓存问题,我探索了bazaarvoice's Configurable Assets Bundle。
这就是我添加到配置类:
@Valid
@NotNull
@JsonProperty
private final AssetsConfiguration assets = new AssetsConfiguration();
,并在主类
@Override
public void initialize(Bootstrap<MyConfiguration> bootstrap) {
// ...
CacheBuilderSpec cacheBuilderSpec = CacheBuilderSpec.disableCaching();
bootstrap.addBundle(new ConfiguredAssetsBundle("/html", cacheBuilderSpec, "/", "index.html", "Static assets"));
}
@Override
public void run(MyConfiguration config, Environment env) {
env.jersey().setUrlPattern("/api/*");
// ...
}
在YAML配置没有变化。
静态文件位于的src /主/资源/ HTML。 如何禁用缓存以使Dropwizard立即显示更改?
第二个问题,我如何让Dropwizard跟随资产目录中的符号链接?
更新
我发现这个在ConfiguredAssetsBundle来源:
// Let the cache spec from the configuration override the one specified in the code
CacheBuilderSpec spec = (config.getCacheSpec() != null)
? CacheBuilderSpec.parse(config.getCacheSpec())
: cacheBuilderSpec;
这肯定将覆盖这是在代码中设置从YAML文件中配置缓存建设者规范。在追加
assets:
cacheSpec: maximumSize=0
到配置,调试器显示最大大小现在为0.但是,行为没有改变。