Class CacheDirective

java.lang.Object
org.eclipse.hono.util.CacheDirective

public final class CacheDirective extends Object
A helper for parsing and creating cache directives compliant with RFC 2616, Section 14.9.
  • Method Details

    • maxAgeDirective

      public static CacheDirective maxAgeDirective(long maxAge)
      Creates a new max-age directive.
      Parameters:
      maxAge - The maximum age in number of seconds.
      Returns:
      The directive.
      Throws:
      IllegalArgumentException - if the given value is less or equal to zero.
    • maxAgeDirective

      public static CacheDirective maxAgeDirective(Duration maxAge)
      Creates a new max-age directive.
      Parameters:
      maxAge - The maximum age.
      Returns:
      The directive.
      Throws:
      IllegalArgumentException - if the given value is less or equal to zero seconds.
    • noCacheDirective

      public static CacheDirective noCacheDirective()
      Creates a new no-cache directive.
      Returns:
      The directive.
    • from

      public static CacheDirective from(String directive)
      Parses a cache directive.
      Parameters:
      directive - The directive to parse.
      Returns:
      The cache directive or null if the directive cannot be parsed.
    • isCachingAllowed

      public boolean isCachingAllowed()
      Checks if this directive allows caching.
      Returns:
      false if caching is not allowed.
    • getMaxAge

      public long getMaxAge()
      Gets the maximum period of time for which a resource may be cached.
      Returns:
      The maximum age in seconds.
    • toString

      public String toString()
      Creates a string representation of this directive.

      The format follows the cache-directive defined in RFC 2616, Section 14.9.

      Overrides:
      toString in class Object
      Returns:
      The cache directive which can be included, e.g. in a Cache-Control header.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object