Context: Adding a feature to an Electron
app to check license data, etc. on start up by sending a query string using XMLHttpRequest
to a remote server. In my testing rig, after a fresh launch an initial request will take 3-4 seconds but subsequent requests return immediately. That worries me.
So a caching issue? I haven't done much network stuff but searching around I saw this (How to clear the cache data in Electron(atom shell)?). Alas, it does not seem to make a difference. I have also tried adding a timestamp to the end of the query string to try to force a new request.
Am I doing something obviously wrong? I've upgraded to the latest version of Electron and have seen no difference.
function clearCache() {
var win = remote.getCurrentWindow();
win.webContents.session.clearStorageData(null, () => {
// this NEVER gets called
console.log('session cleared');
});
win.webContents.session.clearCache(function () {
// this DOES get called
console.log('cache cleared', (new Date()).getTime());
});
}
// attempt to force new request
var timestamp = (new Date()).getTime();
obj.timestamp = timestamp;
var url = domain + queryString.stringify(obj);
xhttp.open("GET", url);
xhttp.timeout = 1000 * 30;
xhttp.send();