Class ETagWebRequestor
- All Implemented Interfaces:
WebRequestor
The ETagWebRequestor caches all GET-requests with an ETag header field in a SoftHashMap and
uses the ETag on the next request as If-None-Match header field if the same URL is requested.
Is the response status code 304 (NOT MODIFIED) the old response from cache is used.
Attention: even 304 responses count as request at Facebook and so they count against the throttling limits. Facebook suggests to use them for data that change only frequently
Further information regarding ETag at Facebook can be found here: https://developers.facebook.com/blog/post/627/
Attention 2: If excessively used with a lot of URLs, the SoftHashMap can lead to a
performance degradation
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class com.restfb.DefaultWebRequestor
DefaultWebRequestor.HttpMethodNested classes/interfaces inherited from interface com.restfb.WebRequestor
WebRequestor.Request, WebRequestor.Response -
Field Summary
Fields inherited from class com.restfb.DefaultWebRequestor
HEADER_CONTENT_TYPE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected WebRequestor.ResponsecreateResponse(java.net.http.HttpResponse<InputStream> httpResponse, Map<String, List<String>> headers) protected voidcustomizeRequest(java.net.http.HttpRequest.Builder builder, WebRequestor.Request request, DefaultWebRequestor.HttpMethod httpMethod) Hook method that lets subclasses tweak theHttpRequest.Builderbefore the request is sent.booleanreturn if cache is used.static voidsetMapSupplier(Supplier<Map<String, ETagWebRequestor.ETagResponse>> mapSupplier) Override the mapSupplier, it needs to be some implementation of theMapinterface.voidsetUseCache(boolean useCache) activate/deactivate the ETag-Cache for the next request.Methods inherited from class com.restfb.DefaultWebRequestor
closeQuietly, createHttpClientBuilder, executeDelete, executeGet, executePost, getHttpClient, initHeaderAccessToken, isAutocloseBinaryAttachmentStream, openConnection, setAutocloseBinaryAttachmentStream, write
-
Constructor Details
-
ETagWebRequestor
public ETagWebRequestor()
-
-
Method Details
-
customizeRequest
protected void customizeRequest(java.net.http.HttpRequest.Builder builder, WebRequestor.Request request, DefaultWebRequestor.HttpMethod httpMethod) Description copied from class:DefaultWebRequestorHook method that lets subclasses tweak theHttpRequest.Builderbefore the request is sent.Typical customizations include adding extra headers or adjusting timeouts per request type. This implementation is a no-op.
- Overrides:
customizeRequestin classDefaultWebRequestor- Parameters:
builder- the builder for the outbound requestrequest- the logical RestFB request that triggered this HTTP callhttpMethod- the HTTP method used for the call
-
createResponse
protected WebRequestor.Response createResponse(java.net.http.HttpResponse<InputStream> httpResponse, Map<String, List<String>> headers) throws IOException- Overrides:
createResponsein classDefaultWebRequestor- Throws:
IOException
-
isUseCache
return if cache is used.- Returns:
trueif ETag-Cache is used,falseif not
-
setUseCache
activate/deactivate the ETag-Cache for the next request.when deactivated, the ETag-Cache is *not* deleted
- Parameters:
useCache- flag to dis/enable the cache during runtime
-
setMapSupplier
Override the mapSupplier, it needs to be some implementation of theMapinterface.You have to set this before the
ETagWebRequestorobject is created. While building it, the mapSupplier is used- Parameters:
mapSupplier- the supplier, that returns a new Map,
-