Find file
Fetching contributors…
Cannot retrieve contributors at this time
129 lines (83 sloc) 3.51 KB

Spring MVC Cache Control

Maven Central Build Status

Spring MVC Cache Control is an extension to Spring MVC that aims to simplify implementing HTTP/1.1 Cache-Control headers for annotated MVC controllers.


Add Spring MVC Cache Control to Your Project.

Maven Projects


Gradle Projects

compile 'net.rossillo.mvc.cache:spring-mvc-cache-control:1.1.1-RELEASE'


Simply include net.rossillo.spring.web.mvc.CacheControlHandlerInterceptor in your Spring MVC configuration.

XML Web Application Context

    <bean class="net.rossillo.spring.web.mvc.CacheControlHandlerInterceptor" />

For XML contexts, this usually defaults to ${appName}-servlet.xml

Java Web Application Context

public class WebMvcConfig extends WebMvcConfigurerAdapter implements WebMvcConfigurer
    public void addInterceptors(InterceptorRegistry registry)
        registry.addInterceptor(new CacheControlHandlerInterceptor());

Annotate Your Controllers

Use the @CacheControl annotation on either (or both) type level @Controllers or method level @RequestMappings. The handler interceptor will read the annotations and generate HTTP/1.1 compliant cache-control headers. For example:

public final class DemoController {

     * Public home page, cacheable for 5 minutes.
    @CacheControl(maxAge = 300)
    @RequestMapping({"/", "/"})
    public String handleHomePageRequest(Model model) {

See our spring-mvc-cache-control-demo project for full details.

Building from Source

  1. Clone the repository from GitHub:

    $ git clone git://
  2. Navigate into the cloned repository directory:

    $ cd spring-mvc-cache-control
  3. The project uses Gradle to build:

    $ ./gradlew build

IDE Integration

IntelliJ IDEA

IDEA 13+ natively support Gralde projects. Simply choose to import an existing project and select the build.gradle file. Tick the checkbox to use the Gradle wrapper.


To generate Eclipse metadata (.classpath and .project files), use the following Gradle task:

$ ./gradlew eclipse

Once complete, you may then import the projects into Eclipse as usual:

File -> Import -> Existing projects into workspace


Use the following Gradle task to build the JavaDoc

$ ./gradlew javadoc

Note: The result will be available in 'spring-mvc-cache-control/build/docs/javadoc'.


Contributions are always welcome. Fork the repository, create a topic branch and send a pull request.