hi, i have a problem with mi request GET and cache. Any ideas on how to disable caching properly?. thanks
I am fairly sure Corona is not caching anything unless it is instructed from the service or you are re-using the same object. So please post more of your code so we can figure out if it is on the lua side and check your server to make sure that it isn’t set to cache data (the server part I have no idea how to fix).
Add a key-value pair to the end of your URL that has a random number or increasing sequential number that makes the URL unique.
For instance:
"https://mysite.com/some/URL?cb=" .. tostring(math.random(9999999))
If your URL already has key-value pairs, it would be more like:
"https://mysite.com/some/URL?someParam=fred&someOtherParam=barney&cb=" .. tostring(math.random(9999999))
BTW: cb is short for “cache busting”. You could use anything like “george=jetson=”, but cb is short, easy to remember and somewhat “standard”
Most good cache busting schemes will use a more unique value than a random number which could possibly generate the same URL. Random numbers used for simplicity.
You can also set various HTTP headers that can control cache as well, though it’s mostly something the backend manages. Caching is a good thing as it prevents you from downloading something you already have. It prevents you overwhelming their services and you should try and honor their caching requests. Unfortunately servers are frequently mis-configured.
Rob
function db.download_lotNumber()
local URL = IP…"/app1Api/LotNumber"
local function networkListener( event )
if (event.isError) then
else
decodedData = json.decode(event.response)
if(decodedData.error ~= nil) then
else
for k,v in pairs(decodedData) do
end
end
end
end
local headers = {}
headers[“Cache-Control”] = “no-cache”
local params = {}
params.headers = headers
network.request(URL, “GET”,networkListener,params)
end
can i use headers [“Cache-Control”] = “no-cache” ?
that depends on what the server is doing on the other side with that header. Did you try what Rob suggested?
If you want to avoid caching and similar things, couldn’t you just use POST instead of GET?
Hi. I’m using the ROB suggestion. I’m doing the tests to check if it works correctly.
I am fairly sure Corona is not caching anything unless it is instructed from the service or you are re-using the same object. So please post more of your code so we can figure out if it is on the lua side and check your server to make sure that it isn’t set to cache data (the server part I have no idea how to fix).
Add a key-value pair to the end of your URL that has a random number or increasing sequential number that makes the URL unique.
For instance:
"https://mysite.com/some/URL?cb=" .. tostring(math.random(9999999))
If your URL already has key-value pairs, it would be more like:
"https://mysite.com/some/URL?someParam=fred&someOtherParam=barney&cb=" .. tostring(math.random(9999999))
BTW: cb is short for “cache busting”. You could use anything like “george=jetson=”, but cb is short, easy to remember and somewhat “standard”
Most good cache busting schemes will use a more unique value than a random number which could possibly generate the same URL. Random numbers used for simplicity.
You can also set various HTTP headers that can control cache as well, though it’s mostly something the backend manages. Caching is a good thing as it prevents you from downloading something you already have. It prevents you overwhelming their services and you should try and honor their caching requests. Unfortunately servers are frequently mis-configured.
Rob
function db.download_lotNumber()
local URL = IP…"/app1Api/LotNumber"
local function networkListener( event )
if (event.isError) then
else
decodedData = json.decode(event.response)
if(decodedData.error ~= nil) then
else
for k,v in pairs(decodedData) do
end
end
end
end
local headers = {}
headers[“Cache-Control”] = “no-cache”
local params = {}
params.headers = headers
network.request(URL, “GET”,networkListener,params)
end
can i use headers [“Cache-Control”] = “no-cache” ?
that depends on what the server is doing on the other side with that header. Did you try what Rob suggested?
If you want to avoid caching and similar things, couldn’t you just use POST instead of GET?
Hi. I’m using the ROB suggestion. I’m doing the tests to check if it works correctly.