@Immutable public final class CachingWire extends Object implements Wire
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(CachingWire.class) .header(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN) .fetch() .body();
The class is immutable and thread-safe.
Constructor and Description |
---|
CachingWire(Wire wire)
Public ctor.
|
Modifier and Type | Method and Description |
---|---|
Response |
get(Request req,
String home,
Collection<Map.Entry<String,String>> headers,
byte[] content)
Fetch GET request and cache it.
|
Response |
send(Request req,
String home,
String method,
Collection<Map.Entry<String,String>> headers,
byte[] content)
Send request and return response.
|
public Response send(Request req, String home, String method, Collection<Map.Entry<String,String>> headers, byte[] content) throws IOException
send
in interface Wire
req
- Requesthome
- URI to fetchmethod
- HTTP methodheaders
- Headerscontent
- HTTP bodyIOException
- if fails@Cacheable(lifetime=5, unit=MINUTES) public Response get(Request req, String home, Collection<Map.Entry<String,String>> headers, byte[] content) throws IOException
req
- Requesthome
- URI to fetchheaders
- Headerscontent
- HTTP bodyIOException
- if failsCopyright © 2012–2014 jcabi.com. All rights reserved.