1

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();
spring
  • 18,009
  • 15
  • 80
  • 160
  • I don't have an answer but I faced a similar problem building a web portfolio. The problem ended up being that there was a server-side cache in addition to the local cache. I don't know the details of what your remote server is but that may be worth looking into. – nebekerdev Jan 31 '20 at 04:12

0 Answers0