apache / cordova-docs

Apache Cordova Documentation
https://cordova.apache.org/
Apache License 2.0
352 stars 557 forks source link

Cache storage documentation #1210

Open mfulton26 opened 3 years ago

mfulton26 commented 3 years ago

Feature Request

Details on advantages/disadvantages, supported platforms, etc. for the Cache API supported by browsers, etc.

Motivation Behind Feature

Cordova has some great docs for helping when making decisions on where and how to store data but doesn't currently provide information saved about the Cache API which can be used in some cases instead of IndexedDB. Documenting this will help folks make informed decisions.

Feature Description

Document Cache API similar to how localStorage, IndexedDb, Web SQL, etc. are documented.

www/docs/en/dev/cordova/storage/storage.md

Alternatives or Workarounds

Various sites out there have some information about total size limits on iOS, etc. etc. but it is hard to find what applies to apps running inside Cordova/WKWebView.

breautek commented 3 years ago

Based on MDN, it looks like the Cache API is a service worker feature. I'm pretty sure service workers are not supported by the underlying webviews. They are supported in the browser application themselves (e.g. Safari and Chrome) but not the WKWebView / Android System Webview counterpart in which the native apps have access to.

mfulton26 commented 3 years ago

Although caches was introduced with service workers it is available on the window object similar to indexedDb.

https://developer.mozilla.org/en-US/docs/Web/API/Window

mfulton26 commented 3 years ago

Note that the Cache interface is exposed to windowed scopes as well as workers. You don't have to use it in conjunction with service workers, even though it is defined in the service worker spec.

breautek commented 3 years ago

Ah ok! Interesting. If that's the case I'd suspect it to work like the other web storage strategies. I think it should be tested though.

Various sites out there have some information about total size limits on iOS, etc. etc. but it is hard to find what applies to apps running inside Cordova/WKWebView.

I know in Chromium, the web storage quota is not constant. It's dynamic based on the total available disk space available on the device. On devices with large space (> 10GB if I recall) the quota is about 10%, otherwise it's some hard-coded value. It's not documented, but you can find the code in the chromium source code. Which also means these rules are subjected to change, as it's an implementation detail.

For iOS, I don't think there is any such code in the open source WebKit project -- but we do know there are limits. We just don't know how they decide those limits.

mfulton26 commented 3 years ago

Yes, if it could be tested and documented that would be very helpful for reference. Especially for iOS.