HttpUtils2 not showing updated data

tamadon

Active Member
Licensed User
Longtime User
Hello,

I am playing with HttpUtils2 and learning about web service. Anyway, I understand that HttpClient or HttpUtils2 do not cache anything.

However, when I add a new data via the app, or remove a data directly via Phpmyadmin for instance, then try to retrieve updated info, the newly added data is not included nor deleted data is still being shown.

Here's the link to the sample code showing the issue.

http://www.sorry

What am I missing? Thanks in advance for the help.
 
Last edited:

tamadon

Active Member
Licensed User
Longtime User
Ok I tried requesting from the browser and I get the same result as that on the device. Is my server caching the query or something? How do I check this?
 
Upvote 0

tamadon

Active Member
Licensed User
Longtime User
OK I think it's my server caching the query. I'll try disabling caching for this particular database.
 
Upvote 0

tamadon

Active Member
Licensed User
Longtime User
I thought I've solved the issue but now direct query via the browser returns the latest result but not from the device.

I probably have to wait for sometime before getting the latest results from the device.

I've disabled query caching on the server by issuing this command

B4X:
SET GLOBAL query_cache_type = 1

I've also specified SQL_NO_CACHE in the php code where I do not want the SELECT statement to be cached (all of them)

IN my sql my.cnf I have set the following

B4X:
 query_cache_type = 1 // enabled (except SELECT SQL_NO_CACHE ... queries)

I know the above has more to do with the server but why the device is not returning the latest result while requests from browser do?
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
A popular workaround to avoid browser caching of XHR requests is to add a bogus parameter to the request.
The javascript Date object is useful as it'll always return a unique bogus parameter.
A typical request that will avoid browser caching is:

B4X:
var requestUrl='http://my.server.com?key=value&bogus_param='+new Date().getTime();

That javascript will ensure that every requestUrl contains a unique bogus_param value and avoid browser caching.
You could do something very similar in your B4A code.

From the code that you posted it looks like your B4A is querying a PHP script, so another solution is to set a header in the output of the PHP script to disable caching:

PHP:
header('Cache-Control: no-cache, must-revalidate');

Note that the PHP header statement must be executed before any text or other output is output by the script - put that header statement at the very start of your PHP script otherwise you'll get an error such as 'headers already sent'.

Disabling caching in the SQL server is a bad idea - it's more likely that the request is being cached elsewhere and your SQL server is not even being re-queried.
Even so disabling SQL server caching could cause major loss of performance.

Martin.
 
Upvote 0
Top