如何为WebView清空缓存? [英] How to empty cache for WebView?

查看:140
本文介绍了如何为WebView清空缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个必须加载图片的Webview!当我上传这张图片时,我每次都看到和以前一样的图像,我必须重新启动我的应用程序才能看到新图像...
我认为是一个缓存问题......我怎么能解决这个问题?

I have a Webview that must load an image! When I upload this image I see every time the same image as before, and i must reboot my app to see the new image... I think is a cache problem..How can I solve that??

推荐答案

一种快速简便的方法是在加载时将当前时间戳附加到URL上。

One quick and easy method would be to append the current time stamp onto the url whenever you load it.

所以不是加载:

http://www.myhost.com/myimg.jpg

你要加载

http://www.myhost.com/myimg.jpg?12345689

使用像这样的缓存断路器是Web开发中一种非常常用的强制重新加载内容的方法。

Using a cache breaker like this is a very common method in web development to force reloading of content.

我确实做了一些快速的谷歌搜索,它似乎清除了NSURL的缓存无法解决问题。在10.6中,api reloadFromOrigin:可以解决这个问题,但我不知道这是否已经让它进入​​了iphone。

I did do some quick googling and it appears clearing out NSURL's cache won't do the trick. In 10.6 the api reloadFromOrigin: may do the trick, but I'm not aware if this has made it's way onto the iphone yet.

修改:

我发现此页面。看起来您可以使用首选项系统来说明是否使用缓存。没有经过测试,但这是值得关注的。

I found this page in the docs. It looks like you can use the preferences system to say whether or not to use caching. Not tested, but that'd be something to look at.

这篇关于如何为WebView清空缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆