Example usage for org.springframework.web.servlet.mvc WebContentInterceptor setCacheSeconds

List of usage examples for org.springframework.web.servlet.mvc WebContentInterceptor setCacheSeconds

Introduction

In this page you can find the example usage for org.springframework.web.servlet.mvc WebContentInterceptor setCacheSeconds.

Prototype

public final void setCacheSeconds(int seconds) 

Source Link

Document

Cache content for the given number of seconds, by writing cache-related HTTP headers to the response: <ul> <li>seconds == -1 (default value): no generation cache-related headers</li> <li>seconds == 0: "Cache-Control: no-store" will prevent caching</li> <li>seconds > 0: "Cache-Control: max-age=seconds" will ask to cache content</li> </ul> <p>For more specific needs, a custom org.springframework.http.CacheControl should be used.

Usage

From source file:org.bonitasoft.web.designer.config.WebMvcConfiguration.java

/**
 * In Internet Explorer http requests are cached by default. It's a problem when we want to provide a REST API. This interceptor
 * adds headers in the responses to desactivate the cache. NB :  static resources are cached but managed by the resource handlers
 *
 * @param registry//from w  w  w. ja va2  s .co m
 */
@Override
public void addInterceptors(InterceptorRegistry registry) {
    WebContentInterceptor interceptor = new WebContentInterceptor();
    interceptor.setCacheSeconds(0);
    interceptor.setUseExpiresHeader(true);
    interceptor.setUseCacheControlHeader(true);
    interceptor.setUseCacheControlNoStore(true);

    registry.addInterceptor(interceptor);
}

From source file:org.wallride.autoconfigure.WebAdminConfiguration.java

@Override
public void addInterceptors(InterceptorRegistry registry) {
    WebContentInterceptor webContentInterceptor = new WebContentInterceptor();
    webContentInterceptor.setCacheSeconds(0);
    webContentInterceptor.setUseExpiresHeader(true);
    webContentInterceptor.setUseCacheControlHeader(true);
    webContentInterceptor.setUseCacheControlNoStore(true);
    registry.addInterceptor(webContentInterceptor);

    registry.addInterceptor(defaultModelAttributeInterceptor);
    registry.addInterceptor(setupRedirectInterceptor);
}