andreshj87 / RequestCache

Caching and retrying failed HTTP requests.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RequestCache Build Status codecov

-Work in progress-

See: Reactive approach

This is a library that allows you to cache and retry failed HTTP requests. You can interact through this interface:

public interface RequestCache {
  void setRequestIntervalTime(long intervalTimeInMillis);
  void enqueueRequest(RequestModel requestModel);
  void enqueueRequests(List<RequestModel> requestModels);
  boolean sendPendingRequests();
  void cancel();
  void clearRequestsCache();
}

Make sure to provide your requests this way:

new RequestModel.Builder<String>()
  .methodType(MethodType.POST)
  .headers(new HashMap<String, String>())
  .baseUrl("https://api.github.com/")
  .endpoint("users/GigigoGreenLabs/repos")
  .query(new HashMap<String, String>())
  .body("This is the body")
  .build();

ToDo

  • Define a Retry Policy: Manual or Automatic.
  • If automatic, it'd be a good idea to register a Broadcast Receiver subscribed to the following intent-filter android.net.conn.CONNECTIVITY_CHANGE
  • Maybe use AlarmManager to schedule retries.
  • Alternative implementation of RequestQueue using SQLite (or even a plain old file) instead of SharedPreferences. Done
  • Alternative implementation using RxJava to avoid callback hell. Done.
  • Add a cancel method. Done

About

Caching and retrying failed HTTP requests.

License:Apache License 2.0


Languages

Language:Java 100.0%