Disable caching of static assets in Dropwizard

I have a Dropwizard web server with rest api which also serves for static content like html, css, javascript and jpg image. Unfortunately, when I change html or add another image, the server always needs to be restarted to make changes to the action.

Since I thought this might be a caching issue, I explored the bazaarvoice Configurable Assets Bundle .

What I added to the configuration class:

@Valid
@NotNull
@JsonProperty
private final AssetsConfiguration assets = new AssetsConfiguration();

And in the main class

@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/*");
    // ...
}

No changes in the configuration of the barley.

Static files are located in the src / main / resources / html file. How can caching be disabled so Dropwizard shows changes instantly?

, 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. .

+4
1

, , , . ( ), , , .

dropwizard maven eclipse mvn exec:java , exec-maven-plugin. Eclipse , , .

+1

All Articles