Module bus.http

Interface InternalCache


public interface InternalCache
An internal interface for Http's cache. Applications should not implement this interface directly. Instead, they should use Cache to configure a cache for an Httpd instance.
Since:
Java 17+
Author:
Kimi Liu
  • Method Summary

    Modifier and Type
    Method
    Description
    get(Request request)
    Returns the cached response for the given request, or null if no cached response exists or is not suitable.
    put(Response response)
    Stores the given response in the cache and returns a CacheRequest to write the response body, or null if the response cannot be cached.
    void
    remove(Request request)
    Removes any cached entries for the given request.
    void
    Tracks a conditional GET that was satisfied by this cache.
    void
    Tracks an HTTP response that was satisfied by the given cacheStrategy.
    void
    update(Response cached, Response network)
    Updates the stored cached response with headers from the new network response.
  • Method Details

    • get

      Response get(Request request) throws IOException
      Returns the cached response for the given request, or null if no cached response exists or is not suitable.
      Parameters:
      request - The request to get the cached response for.
      Returns:
      The cached response, or null.
      Throws:
      IOException - if an I/O error occurs.
    • put

      CacheRequest put(Response response) throws IOException
      Stores the given response in the cache and returns a CacheRequest to write the response body, or null if the response cannot be cached.
      Parameters:
      response - The response to store.
      Returns:
      A CacheRequest to write the response body, or null.
      Throws:
      IOException - if an I/O error occurs.
    • remove

      void remove(Request request) throws IOException
      Removes any cached entries for the given request. This is called when the client invalidates the cache, such as when making a POST, PUT, or DELETE request.
      Parameters:
      request - The request to remove from the cache.
      Throws:
      IOException - if an I/O error occurs.
    • update

      void update(Response cached, Response network)
      Updates the stored cached response with headers from the new network response. This is called to handle conditional requests. If the stored response has changed since cached was returned, this does nothing.
      Parameters:
      cached - The stale cached response.
      network - The new network response.
    • trackConditionalCacheHit

      void trackConditionalCacheHit()
      Tracks a conditional GET that was satisfied by this cache. This is used for statistics.
    • trackResponse

      void trackResponse(CacheStrategy cacheStrategy)
      Tracks an HTTP response that was satisfied by the given cacheStrategy. This is used for statistics.
      Parameters:
      cacheStrategy - The cache strategy used for the response.