Class CachedResponse

java.lang.Object
org.microproxy.cache.CachedResponse

public final class CachedResponse extends Object
A stored response: status, header fields and body as received, the request header values its Vary named, and when it was requested and received (for the age calculation of RFC 9111 section 4.2.3). Instances are immutable.
  • Constructor Details

    • CachedResponse

      public CachedResponse(String key, Map<String,String> vary, int status, String reason, HttpHeaders headers, byte[] body, long requestTime, long responseTime)
      Creates a stored response and its freshness metadata.
      Parameters:
      key - the URL the response was stored under
      vary - for each field named by Vary (lower-cased), the request's normalized value, or null if the request lacked it
      status - the HTTP status code
      reason - the HTTP reason phrase
      headers - the response header fields
      body - the response body bytes
      requestTime - the request timestamp in epoch milliseconds
      responseTime - the response timestamp in epoch milliseconds
  • Method Details

    • key

      public String key()
      Returns the URL identifying this cached response.
      Returns:
      the URL identifying this cached response
    • vary

      public Map<String,String> vary()
      Returns the request header values selecting this cached variant.
      Returns:
      the request header values selecting this cached variant
    • status

      public int status()
      Returns the stored HTTP status code.
      Returns:
      the stored HTTP status code
    • reason

      public String reason()
      Returns the stored HTTP reason phrase.
      Returns:
      the stored HTTP reason phrase
    • headers

      public HttpHeaders headers()
      Returns a copy of the stored header fields.
      Returns:
      a copy of the stored header fields
    • body

      public byte[] body()
      Returns a copy of the body.
      Returns:
      a copy of the body
    • requestTime

      public long requestTime()
      Returns when the request was sent, in epoch milliseconds.
      Returns:
      when the request was sent, in epoch milliseconds
    • responseTime

      public long responseTime()
      Returns when the response was received, in epoch milliseconds.
      Returns:
      when the response was received, in epoch milliseconds
    • weight

      public long weight()
      Returns roughly how much memory or disk the entry takes.
      Returns:
      roughly how much memory or disk the entry takes
    • toString

      public String toString()
      Overrides:
      toString in class Object