Module methanol

Class CacheControl.Builder

  • Enclosing class:
    CacheControl

    public static final class CacheControl.Builder
    extends java.lang.Object
    A builder of CacheControl instances, with explicit directive setters for request cache directives.

    Methods that accept a Duration drop any precision finer than that of a second, which is the only precision allowed by cache directives representing durations. Additionally, any duration with number of seconds that's larger than Integer.MAX_VALUE is truncated to that value.

    • Method Detail

      • directive

        @CanIgnoreReturnValue
        public CacheControl.Builder directive​(java.lang.String directive)
        Sets the given directive with no argument.
        Throws:
        java.lang.IllegalArgumentException - if directive is invalid
      • directive

        @CanIgnoreReturnValue
        public CacheControl.Builder directive​(java.lang.String directive,
                                              java.lang.String argument)
        Sets the given directive to the given argument. If argument is an empty string, the directive is considered one without argument.
        Throws:
        java.lang.IllegalArgumentException - if either of directive or argument is invalid
      • maxAge

        @CanIgnoreReturnValue
        public CacheControl.Builder maxAge​(java.time.Duration maxAge)
        Sets the max-age directive to the given duration.
        Throws:
        java.lang.IllegalArgumentException - If maxAge doesn't contain a positive number of seconds
      • minFresh

        @CanIgnoreReturnValue
        public CacheControl.Builder minFresh​(java.time.Duration minFresh)
        Sets the min-fresh directive to the given duration.
        Throws:
        java.lang.IllegalArgumentException - If minFresh doesn't contain a positive number of seconds
      • maxStale

        @CanIgnoreReturnValue
        public CacheControl.Builder maxStale​(java.time.Duration maxStale)
        Sets the max-stale directive to the given duration.
        Throws:
        java.lang.IllegalArgumentException - If maxStale doesn't contain a positive number of seconds
      • anyMaxStale

        @CanIgnoreReturnValue
        public CacheControl.Builder anyMaxStale()
        Sets the max-stale directive to accept any stale response.
      • staleIfError

        @CanIgnoreReturnValue
        public CacheControl.Builder staleIfError​(java.time.Duration staleIfError)
        Sets the stale-if-error directive to the given duration.
        Throws:
        java.lang.IllegalArgumentException - If staleIfError doesn't contain a positive number of seconds
      • noCache

        @CanIgnoreReturnValue
        public CacheControl.Builder noCache()
        Sets the no-cache directive.
      • noStore

        @CanIgnoreReturnValue
        public CacheControl.Builder noStore()
        Sets the no-store directive.
      • noTransform

        @CanIgnoreReturnValue
        public CacheControl.Builder noTransform()
        Sets the no-transform directive.
      • onlyIfCached

        @CanIgnoreReturnValue
        public CacheControl.Builder onlyIfCached()
        Sets the only-if-cached directive.
      • build

        public CacheControl build()
        Builds a new Cache-Control.