DEV Community

Discussion on: Caching network requests on the frontend

Collapse
 
nosyminotaur profile image
Harsh Pathak

One of the reasons I used local storage here was simplicity. If I used IndexedDB I'd have better results for multiple requests because they'd all be async.
Also, I'm not saying this is perfect. This is just a start and we have a long way to go to implement perfect caching.

Collapse
 
yellow1912 profile image
yellow1912

I got around this by issuing another promise. Something hacky like this:

  1. If cache key does not exist, mark that cache key as loading
  2. Start loading, once done then unmark the loading key. Resolve all promises (see below)
  3. If any request (same URL etc) sent within the loading phase, return a promise.