lisaogren / axios-cache-adapter

Caching adapter for axios. Store request results in a configurable store to prevent unneeded network requests.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve documentation around using localForage drivers with axios-cache-adapter

ahayes91 opened this issue · comments

I'm using axios-cache-adapter for client-side caching, and I'm updating our instance to use a localForage store instead of relying on in-memory storage.
https://www.npmjs.com/package/axios-cache-adapter#use-localforage-as-cache-store has some code examples on creating the localForage store to be used with axios-cache-adapter, and the example provided specifically excludes localforage.WEBSQL as a driver from the list. I tried using localforage.WEBSQL on its own as the driver for my own implementation of axios-cache-adapter for kicks, and found that the caching didn't work on MacOS Chrome at all with WebSQL.
Is this a known issue with axios-cache-adapter & WebSQL?
Any chance we can improve the documentation around the driver setting, and perhaps explain the use of the memoryDriver from localforage-memoryStorageDriver?

Were you able to find a solution for this?

@nql5161 nope, couldn't get WebSQL working so we ended up using LocalStorage as the driver. Here are the general findings I documented internally before I had to move on:

  • WebSQL didn't seem to work at all for caching requests in Chrome & MacOS when we tried it on its own (all network calls were being repeated, even if the maxAge of the request was greater than 0).
  • IndexedDB was quite reliable on Chrome, Safari, Firefox on Mac OS, and on Chrome, Firefox, and Edge on Windows, but didn't support database cleanup very well. We spent a lot of time on this one:
    • We tried to use dropInstance method on logout to delete the databases, but it made the logout process several seconds longer and significantly decreased UI performance in redirecting the user back to the login screen. (This may be something specific to our implementation of a logout mechanism though.)
    • If you didn't use dropInstance, it left behind orphaned databases in the browser, including a default duplicated store named "localforage". There was no option to iterate through databases and delete them, as per localForage/localForage#719. https://gist.github.com/rmehner/b9a41d9f659c9b1c3340 shows a way to delete all IndexedDB databases, but this method isn't supported by Firefox or Safari.
    • It didn't support multiple tab browser sessions on the same store (the second tab would hang completely and network requests that needed to go through the store couldn't be completed).
  • LocalStorage is always the fallback for Firefox in private mode, as IndexedDB isn't supported in private mode.
  • localforage-memoryStorageDriver in-memory storage is the fallback in case any older versions of browsers don't support localStorage (i.e. network calls will still be cached, but you can't view the cache in the browser in the Storage pane of developer tools).