简体   繁体   中英

Aurelia Http fetch returns cached data

So I am new to Aurelia and web development in general.

Currently I have a view with a table of data. After editing an entry and returning to the table I call my function to make another API call but instead my browser returns a 304 not modified (though in the database the values have been updated).

When I enable "always refresh from server" in Edge I get the results as I would expect. Is there some way of telling this Http request to always call the API and not from the cache?

Off the top of my head, you could alter the url you're hitting to have some junk at the end of it.

this.http.get(url + "?_t=" + new Date().getTime(), data).done(function(values) {
  //do stuff
});

Not pretty, but it should work.

Similarly, you could construct your own call to use.

nonCachedGet(url, data) {
  return this.http.createRequest(url)
                  .asGet()
                  .withContent(data)
                  .withParams({ _t: new Date().getTime() })
                  .send();
}

It doesn't look like there are any specific settings telling the built in request methods not to cache, though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM