HTTP plugin cache request and response of my API call

#1

I am using cordova-plugin-advanced-http and call api through this plugin all transaction works well but as and when I got 401 error from server due to some issue at server side after this issue I will get same response all time.

It will cache my api response and never be get proper data.

If I uninstall app and again reinstall it its working as expected same issue will our if I got any error like 401 or 404 from server side.

I want to disable caching of my request & response while calling any API.

Help me If I am doing any mistake in it.

Thanks!

#2

Hi, I am getting a similar error in Ionic 4 and I can’t tell for sure if cache is the problem or something else. Did you find a solution?

#3

Hi,

I have already solved my problem long back and yes its cache issue which Ionic internally caching my request and response in cookies.

So to solve this problem I used to call clear cache from cookies method of HTTP plugin.

Use below function before call any API:

this.httpPlugin.clearCookies();

Also refer this thread on Stackourflow for more details.

Ref link: https://stackoverflow.com/questions/52698596/how-to-stop-caching-my-http-request-response-in-ionic-3

Hope this will helps to solve your issue.

Thanks!

#4

I’ve tried that, but no success. The problem is that after a timed out request on lack of internet connection ({“status”:1,“error”:“The request timed out: java.net.SocketTimeoutException: timeout”}, for example wifi connected but without internet), all the other requests get the same answer, even after connection comes back.
This happens on any request that doesn’t reach the server, cordova http plugin returns the old answer after connection back, and any other request (even different type, for example post after get) for that server fail.

#5

May I know where you ware clearing your cookies or calling clearCookies() method ?

#6

Sure, I am calling the clearCookies() method just before making the request

this.http.clearCookies();
this.http.sendRequest(testURL, { method: "get", timeout: 10, headers: { 'Connection': 'close', 'Pragma': 'no-cache', 'Cache-control': 'no-cache, max-age=0' } })

      .then(res1 => {
        ...
      })
      .catch(err1 => {
       ...
      });

After an error on lack of connection (connection timeout or ssl handshake fail), any subsequent request (doesn’t matter if it’s a get or post) for that base url gets the same status of the previous error.

#7

Hello,

I am wondering if you solve the problem yet?
because I am facing the same :frowning: