B4J Question HttpUtils and cache , cookie or ... ?

MarcoRome

Expert
Licensed User
Longtime User
Hi All.
I have this problem, when I try to read the data coming from an API call (woocommerce) they come back correct.
It seems in any case that in B4J they remain "stored", because if I add a test order or delete the same, trying the call in the browser in GET ( type: https://example.com/wp-json/wc/v3/orders?consumer_key=xxxxx&consumer_secret=yyyyy) the data are immediately updated, while in B4J using httputils they are visible still the "old" data, the same thing happens even if I use the Tools JsonTree.jar the old data is displayed.
does jOkhttutils use cookies, cache or something else??
Any suggestions ?
Thank you
Marco
 

DonManfred

Expert
Licensed User
Longtime User
okhttputils2 does not cache anything.

If it is important to use cookies then you have to do it by yourself.

Best is to upload a small project showing the problem. Ideally with a real url not a dummy
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
okhttputils2 does not cache anything.

If it is important to use cookies then you have to do it by yourself.

Best is to upload a small project showing the problem. Ideally with a real url not a dummy

Hello dear Don.
We can also connect a hard link but the problem would still not be solved.
Explaining myself better, everything works, that is, when the query is made
( type: https://example.com/wp-json/wc/v3/orders?consumer_key=xxxxx&consumer_secret=yyyyy)
the results are read, but in the event that other orders arrive through woocoomerce or, for example, some order is cancelled, by rerunning the query, the data are not updated but are exactly the same as before.
So even if I report the example link, we should work on it together, because to understand I would have to cancel an order through woocommerce and you would have to repeat the query.

As said, if you paste the query on the browser, the update is immediate, the json already returns with the updated data while with jokutils you can see them after about 30 minutes.
That's why I thought there was a cookie to another that "delayed" the results
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i recently suggested a possible solution to a similar problem:

https://www.b4x.com/android/forum/threads/okhttputils2-hard-refresh.144152/#post-914786
post #6

my suggestion worked in that case. you may wish to try it.

first you say the old data is displayed with okhttputils, then you say the new data is available 30 minutes
later. which is it? please explain what you are doing: you wait 30 minutes and then try again?
or you do other things (like watch some world cup on tv) and then, somehow, 30 minutes later, the new
data appears by itself? 30 minutes, not 25? not 20?

if cookies are the problem (that is, the server expects one), it is possible to capture the server's response
headers (including cookies) with okhttp. they are captured in a list:
list = job.response.getheaders.get("set-cookie"). note: your server may use "Set-Cookie", not "set-cookie".
case is important in this instance. the cookie list will be null if you use the wrong one...

once you have the cookies, you can simply return them with your next query as a request header.
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
i recently suggested a possible solution to a similar problem:

https://www.b4x.com/android/forum/threads/okhttputils2-hard-refresh.144152/#post-914786
post #6

my suggestion worked in that case. you may wish to try it.

first you say the old data is displayed with okhttputils, then you say the new data is available 30 minutes
later. which is it? please explain what you are doing: you wait 30 minutes and then try again?
or you do other things (like watch some world cup on tv) and then, somehow, 30 minutes later, the new
data appears by itself? 30 minutes, not 25? not 20?

if cookies are the problem (that is, the server expects one), it is possible to capture the server's response
headers (including cookies) with okhttp. they are captured in a list:
list = job.response.getheaders.get("set-cookie"). note: your server may use "Set-Cookie", not "set-cookie".
case is important in this instance. the cookie list will be null if you use the wrong one...

once you have the cookies, you can simply return them with your next query as a request header.
Hi @drgottjr
Thank you for your answer.
In any case, that wasn't the problem.
The same was fixed, by disabling/configuring the LiteSpeed plugin.

Basically, when liteSpeed is not configured / disabled, it caches the call, and therefore when it is recalled, the "old" data is seen, which is updated from time to time.
Although it remains a mystery why using the get call via browser the problem does not exist.

 
Upvote 0
Top