Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
In this blog, We are going to learn about how to achieve Retrofit Offline Caching in Android.
We know that OkHttp is the default HttpClient for Retrofit.OkHttp comes with a powerful component Interceptors.
We have two types of interceptors.
Using Interceptors you can read and modify the requests. And obviously, we’ll add Cache-control on the responses.
Cache-control is a header used to specify caching policies in client requests and server responses.
Note: You can only cache the GET requests.
Code :
The code for the MainActivity.kt is given below:
The code for the APIService.kt is given below:
Note: Don’t forget to add Internet permission in your manifest file.
Now we have done. Hope this blog will help you to achieve caching retrofit requests in android.
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Excellent work, fast, good quality and understood the brief perfectly! Quick responses developing the project and very good cooperation. I suggest to anyone.
Stathis Plakidas
USA
India
Global
Name
Email
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.