Class FcWire

java.lang.Object
com.jcabi.http.wire.FcWire
All Implemented Interfaces:
Wire

@Immutable public final class FcWire extends Object implements Wire
Wire that caches GET requests.

This decorator can be used when you want to avoid duplicate GET requests to load-sensitive resources, for example:

 String html = new JdkRequest("http://goggle.com")
   .through(FileCachingWire.class)
   .header(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN)
   .fetch()
   .body();

You can also configure it to flush the entire cache on certain request URI's, for example:

new JdkRequest(uri)
   .through(CachingWire.class, "GET /save/.*")
   .uri().path("/save/123").back()
   .fetch();

The regular expression provided will be used against a string constructed as an HTTP method, space, path of the URI together with query part.

The class is immutable and thread-safe.

Since:
1.16
  • Constructor Details

    • FcWire

      public FcWire(Wire wire)
      Public ctor.
      Parameters:
      wire - Original wire
    • FcWire

      public FcWire(Wire wire, String flsh)
      Public ctor.
      Parameters:
      wire - Original wire
      flsh - Flushing regular expression
    • FcWire

      public FcWire(Wire wire, String flsh, String path)
      Public ctor.
      Parameters:
      wire - Original wire
      flsh - Flushing regular expression
      path - Path for the files
    • FcWire

      public FcWire(Wire wire, String flsh, com.jcabi.http.wire.FcCache fcc)
      Public ctor.
      Parameters:
      wire - Original wire
      flsh - Flushing regular expression
      fcc - Cache
  • Method Details

    • send

      public Response send(Request req, String home, String method, Collection<Map.Entry<String,String>> headers, InputStream content, int connect, int read) throws IOException
      Description copied from interface: Wire
      Send request and return response.
      Specified by:
      send in interface Wire
      Parameters:
      req - Request
      home - URI to fetch
      method - HTTP method
      headers - Headers
      content - HTTP body
      connect - The connect timeout
      read - The read timeout
      Returns:
      Response obtained
      Throws:
      IOException - if fails