Check Mobile App
Read now
Start a Project

Retrofit Offline Caching in Android

Save

Retrofit Offline Caching in Android

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.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


1 comments

  • John
    Thanks bro
  • css.php

    Very good company, we did get app extension for Magento 2 website. The support was very good they help us through the process. Webkul team is very supportive, I would recommend them.

    Yasser Mohamed

    Yasser Mohamed

    Talk to Sales

    Global

    Live Chat
    Start a Project

      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home