Class HttpCache.Builder

java.lang.Object
org.microproxy.cache.HttpCache.Builder
Enclosing class:
HttpCache

public static final class HttpCache.Builder extends Object
Options for HttpCache.
  • Method Details

    • store

      public HttpCache.Builder store(CacheStore store)
      Where responses are kept (default: 64 MiB in memory).
      Parameters:
      store - the backing response store
      Returns:
      this builder
    • maxEntrySize

      public HttpCache.Builder maxEntrySize(int bytes)
      The largest response body stored (default 8 MiB); larger ones stream past.
      Parameters:
      bytes - the maximum stored response body size in bytes
      Returns:
      this builder
    • shared

      public HttpCache.Builder shared(boolean shared)
      Whether the rules for shared caches apply (default true). False makes a private cache.
      Parameters:
      shared - whether shared-cache rules apply
      Returns:
      this builder
    • offline

      public HttpCache.Builder offline(boolean offline)
      Answer only from the cache, never contacting servers (default false).
      Parameters:
      offline - whether to answer only from cached responses
      Returns:
      this builder
    • serveStaleOnError

      public HttpCache.Builder serveStaleOnError(boolean serveStaleOnError)
      Serve stale entries when servers cannot be reached (default true).
      Parameters:
      serveStaleOnError - whether stale responses may be served on upstream failures
      Returns:
      this builder
    • heuristic

      public HttpCache.Builder heuristic(double fraction, Duration max)
      The heuristic lifetime: this fraction of the time since Last-Modified, at most max.
      Parameters:
      fraction - the fraction of time since Last-Modified used as a heuristic lifetime
      max - the maximum heuristic freshness lifetime
      Returns:
      this builder
    • clock

      public HttpCache.Builder clock(Clock clock)
      The clock for ages and freshness (for tests).
      Parameters:
      clock - the clock used for timestamps and expiry checks
      Returns:
      this builder
    • name

      public HttpCache.Builder name(String name)
      The cache's name in Cache-Status (default "MicroProxy").
      Parameters:
      name - the cache name reported in Cache-Status
      Returns:
      this builder
    • build

      public HttpCache build()
      Creates the configured HTTP cache.
      Returns:
      the configured HTTP cache