Android WebView cache details

Android WebView cache details

1、 There are two cache types:

Page cache: page or resource data such as HTML, JS and CSS when loading a web page. These cache resources are generated due to the behavior of the browser. Developers can indirectly affect these cache data only by configuring the HTTP response header to affect the behavior of the browser. The cached index is placed in: / data / data / / databases, and the corresponding file is placed in: / data / data / package_ Data cache under name / cache / webviewcachechromum: it is divided into appcache and DOM storage. These cache resources can be controlled by our developers

AppCache:

We can selectively buffer everything in a web browser, from pages and images to scripts, CSS, and so on. Especially useful when it comes to CSS and JavaScript files applied to multiple pages of a website. Its size is usually 5m at present. On Android, you need to manually enable (setappcacheenabled), set the path (setappcachepath) and capacity (setappcachemaxsize), and use applicationcache.db in Android to save appcache data!

DOM Storage:

Store some simple data that can be solved by using key / value pairs. Depending on the scope of action, there are session storage and local storage, which are used for session level storage (the page disappears when it is closed) and localized storage (the data will never expire unless it is actively deleted). DOM storage (setdomstorageenabled) can be manually enabled in Android, Set storage path (setdatabasepath) WebKit in Android will generate two files for domstorage (my_path / localstorage / http_blog. CSDN. Net_0. Localstorage and my_path / databases. DB)

2、 Five cache modes of WebView:

LOAD_ NO_ Cache: do not use cache, only get data load from the network_ CACHE_ Only: do not use the network, only read the local cache data load_ Default: determines whether to load data from the network according to cache control_ CACHE_ Normal: API level 17 has been abandoned. Starting from API level 11, it works the same as load_ Default mode load_ CACHE_ ELSE_ Network, as long as it exists locally, uses the data in the cache regardless of whether it is expired or no cache

3、 Setting of WebView cache mode:

webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);// Or other modes

According to the demand, the caching strategy can be: judge whether there is a network using load_ DEFAULT/LOAD_ NO_ CACHE

None: use load_ CACHE_ ELSE_ NETWORK

4、 Delete cached data:

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>