2

In retrofit, caching the GET request is easy!

After googling for sometime, got to know that we can't cache the POST request through Retrofit/OkHttp.

Is there any workaround or better approach to handle this limitation?

In GET request, url is the key to retrieve the cache. For POST request, if there is some provision for dynamic tag in the place of url, we can easily make it work.

Kindly share your comments.

Thanks in advance!

Karthi R
  • 1,338
  • 10
  • 25
  • 3
    In api scenario. Post request is to create new resource. Why you want to cache that? – Kamran May 29 '16 at 16:00
  • Based on the content of POST body, I need to maintain the cache. – Karthi R May 29 '16 at 16:14
  • So, what if a url accepted both a GET and POST? How do you cache that? I think you also need to specify the method type as part of the key – OneCricketeer May 29 '16 at 16:26
  • As I said, If we have control over the caching key(Eg. some dynamic tag based on request input). we can make it work. – Karthi R May 29 '16 at 16:34
  • Are you already using an interceptor to cache the get? And by cache a request, do you mean you cache the server response the first time, and resend that same response for an identical request, rather than going back to the server? Or something else? – nasch May 29 '16 at 23:25
  • @nash; Yes, I'm using interceptors to cache the GET requests. And same as you said. – Karthi R May 30 '16 at 03:02

0 Answers0