Annotation Type CacheControl


  • @Documented
    @Target({TYPE,METHOD})
    @Retention(RUNTIME)
    @StableMinor(version="14.1",
                 sinceVersion="8.0")
    public @interface CacheControl
    An annotation which specifies the Cache-Control header to include in the response produced by the annotated method.

    This annotation may be applied to a REST method or to its class. If it is present in both the method and the class, the one present in the method is the one used.

    When no Cache-Control header is present in the response, a header according to this annotation present in the method or class will be added to the response (note that if the values of this annotation corresponds to an empty header, it will not be added).

    If the response already has a Cache-Control header present, it is not modified, independently of this annotation. Any Cache-Control header set in the response is considered to override this annotation or the default behavior.

    If neither a Cache-Control header is in the response or this annotation is applied, LumisXP includes the following response header as default:
    Cache-Control: private, no-cache, no-store, no-transform

    Example:

     @CacheControl(maxAge=60)
     public class MyRest
     {
            @GET
            @Path("/hello1")
            @Produces({MediaType.TEXT_PLAIN})
            public String helloCachedFor60Seconds()
            {
                    // since this method does not have @CacheControl but the class has it, the one in the class will be used, specifying max-age=60
                    // Note that the actual use of cache depends on the HTTP client being used.
                    return new java.util.Date().toString(); 
            }
     
            @GET
            @Path("/hello2")
            @Produces({MediaType.TEXT_PLAIN})
            @CacheControl
            public String helloNoCacheControlHeader()
            {
                    // the @CacheControl in this method will not generate any Cache-Control header
                    return new java.util.Date().toString(); 
            } 
     
            @GET
            @Path("/hello3")
            @Produces({MediaType.TEXT_PLAIN})
            @CacheControl(noCache=true)
            public String helloNoCache()
            {
                    // the @CacheControl annotation in this method will generate a no-cache header
                    return new java.util.Date().toString(); 
            } 
     } 
    Since:
    8.0.0
    Version:
    $Revision: 24683 $ $Date: 2021-08-23 18:55:58 -0300 (Mon, 23 Aug 2021) $
    See Also:
    HTTP Cache-Control header specification
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      boolean isPrivate
      Controls the private setting of the Cache-Control header.
      int maxAge
      Controls the max-age setting of the Cache-Control header.
      boolean mustRevalidate
      Controls the must-revalidate setting of the Cache-Control header.
      boolean noCache
      Controls the no-cache setting of the Cache-Control header.
      boolean noStore
      Controls the no-store setting of the Cache-Control header.
      boolean noTransform
      Controls the no-transform setting of the Cache-Control header.
      boolean proxyRevalidate
      Controls the proxy-revalidate setting of the Cache-Control header.
      int sharedMaxAge
      Controls the s-max-age setting of the Cache-Control header.
    • Element Detail

      • isPrivate

        boolean isPrivate
        Controls the private setting of the Cache-Control header.
        Returns:
        true if private must be included in the the Cache-Control header.
        Since:
        8.0.0
        See Also:
        HTTP Cache-Control header specification
        Default:
        false
      • noCache

        boolean noCache
        Controls the no-cache setting of the Cache-Control header.
        Returns:
        true if no-cache must be included in the the Cache-Control header.
        Since:
        8.0.0
        See Also:
        HTTP Cache-Control header specification
        Default:
        false
      • noStore

        boolean noStore
        Controls the no-store setting of the Cache-Control header.
        Returns:
        true if no-store must be included in the the Cache-Control header.
        Since:
        8.0.0
        See Also:
        HTTP Cache-Control header specification
        Default:
        false
      • noTransform

        boolean noTransform
        Controls the no-transform setting of the Cache-Control header.
        Returns:
        true if no-transform must be included in the the Cache-Control header.
        Since:
        8.0.0
        See Also:
        HTTP Cache-Control header specification
        Default:
        false
      • mustRevalidate

        boolean mustRevalidate
        Controls the must-revalidate setting of the Cache-Control header.
        Returns:
        true if must-revalidate must be included in the the Cache-Control header.
        Since:
        8.0.0
        See Also:
        HTTP Cache-Control header specification
        Default:
        false
      • proxyRevalidate

        boolean proxyRevalidate
        Controls the proxy-revalidate setting of the Cache-Control header.
        Returns:
        true if proxy-revalidate must be included in the the Cache-Control header.
        Since:
        8.0.0
        See Also:
        HTTP Cache-Control header specification
        Default:
        false
      • maxAge

        int maxAge
        Controls the max-age setting of the Cache-Control header.
        Returns:
        the number of seconds for which the response should be considered fresh, or -1 to disable this setting.
        Since:
        8.0.0
        See Also:
        HTTP Cache-Control header specification
        Default:
        -1
      • sharedMaxAge

        int sharedMaxAge
        Controls the s-max-age setting of the Cache-Control header.
        Returns:
        the number of seconds for which the response should be considered fresh in shared caches, or -1 to disable this setting.
        Since:
        8.0.0
        See Also:
        HTTP Cache-Control header specification
        Default:
        -1