2

In my case, I want to load data from Cache. If there is cache load from cache else load from network. How can I use caching in Ion?

    private void loadION() {
    final ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setMessage("loading");
    progressDialog.show();
    Ion.with(getApplicationContext()).load(url)
            .setBodyParameter("tag", "annual_schedule").asString()
            .setCallback(new FutureCallback<String>() {
                @Override
                public void onCompleted(Exception e, String str) {
                    Message.Toast(getApplicationContext(), str);
                    progressDialog.dismiss();
                }
            });
}
DroidLearner
  • 2,115
  • 5
  • 31
  • 50

1 Answers1

6

Ion will automatically cache GET requests. This is a POST request, and can not be cached by the library.

Furthermore, cached requests can't be used right away, since disk I/O is still treated as a blocking call. It will still be an asynchronous request.

koush
  • 2,972
  • 28
  • 31
  • Hi koush,i always obtain 'Response is not cacheable' with get request and json content. I've, also, installed root cache as http://developer.android.com/reference/android/net/http/HttpResponseCache.html but it doesn't works – Premier Mar 04 '15 at 07:42
  • @Premier You'll need to set the Cache-Control header server side for Ion to cache the GET request. – jlhonora Dec 01 '15 at 21:02