1

My application is using HttpRequest for many times. is there a way to not call Rest for every time?

i.e How maintain cache for Api Request call. and it should also be worked when there is no internet

Thanks in advance.

2

1 Answer 1

3

Android have own classes to cache responses. To turn cache you should call HttpResponseCache.install method. Such as

HttpResponseCache.install(getCacheDir(), 10 * 1024 * 1024); //10MB cache size

and when you open connection call

connection.setUseCaches(true);

Somthing like this

URL url = new URL("http://site.com/");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setUseCaches(true);

Also you can read this topic

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.