How to write webpage to cache?

半城伤御伤魂 提交于 2019-12-31 05:19:09

问题


I want to load a webpage, and if it was already loaded before and not modified then load it from cache. If it is found to be modified, then clear this page in the cache and reload.

How can I do this?

  1. Write the webpage into the cache
  2. Find the webpage in the cache
  3. Show the webpage from the cache
  4. Clear the cache and load a new version if the page was modified

Please help me. It would be awesome if can show me the code for each of the above.
Best regards.


回答1:


If you are ok with using Webview then LOAD_NORMAL is for u.

webView.getSettings().setCacheMode(WebSettings.LOAD_NORMAL); webView.loadUrl(HELPER.SERVER_BASE_LINK + "ads/s_image" + (i+1) + ".jpg");

It uses cache to load the webpage unless the page is modified, which is also mentioned in the description of setCacheMode();

http://developer.android.com/reference/android/webkit/WebSettings.html#setCacheMode%28int%29

It takes a few minutes (within 5) to reload the modified page. It is probably the poling time of Android for checking expired pages. I have tried it myself, but I felt bugs in it, sometimes it just doesn't load the cache. It might be that android is taking my cache back too quickly, which is usually not the case.

Using cache with browsers will have some similar method.



来源:https://stackoverflow.com/questions/9750581/how-to-write-webpage-to-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!