UIWebView的缓存策略,清除cookie
缓存策略 NSURLRequestCachePolicy
NSURLRequestUseProtocolCachePolicy
缓存策略定义在 web 协议实现中,用于请求特定的URL。是默认的URL缓存策略
Specifies that the caching logic defined in the protocol implementation, if any, is used for a particular URL load request. This is the default policy for URL load requests.
NSURLRequestReloadIgnoringLocalCacheData
从服务端获取数据,忽略本地缓存
Specifies that the data for the URL load should be loaded from the originating source. No existing cache data should be used to satisfy a URL load request.
NSURLRequestReloadIgnoringLocalAndRemoteCacheData
不仅忽略本地的缓存数据,还忽略中间网络媒介(如代理服务器)忽略缓存。直接从最原始的服务器拿取
Specifies that not only should the local cache data be ignored, but that proxies and other intermediates should be instructed to disregard their caches so far as the protocol allows.
NSURLRequestReloadIgnoringCacheData
被NSURLRequestReloadIgnoringLocalCacheData替换了
Replaced by NSURLRequestReloadIgnoringLocalCacheData.
NSURLRequestReturnCacheDataElseLoad
已经存在的缓存数据用于请求返回,不管它的过期日期和已经存在了多久。如果没有请求对应的缓存数据,从数据源读取
Specifies that the existing cached data should be used to satisfy the request, regardless of its age or expiration date. If there is no existing data in the cache corresponding the request, the data is loaded from the originating source.
NSURLRequestReturnCacheDataDontLoad
已经存在的缓存数据用于请求返回,不管它的过期日期和已经存在了多久。如果没有请求对应的缓存数据,不要去数据源读取,该请求被设置为失败,这种情况多用于离线模式
Specifies that the existing cache data should be used to satisfy a request, regardless of its age or expiration date. If there is no existing data in the cache corresponding to a URL load request, no attempt is made to load the data from the originating source, and the load is considered to have failed. This constant specifies a behavior that is similar to an “offline” mode.
NSURLRequestReloadRevalidatingCacheData
已经存在的缓存数据先去数据源验证有效性,如果无效,将从数据源获取
Specifies that the existing cache data may be used provided the origin source confirms its validity, otherwise the URL is loaded from the origin source.
NSURLRequestUseProtocolCachePolicy 和 NSURLRequestReloadRevalidatingCacheData 区别
个人意见,仅供参考,如有错误,请指出来,这对我很重要,谢谢
NSURLRequestReloadRevalidatingCacheData 是一定要和原始的数据源验证 cache 是否有效。
而NSURLRequestUseProtocolCachePolicy 是根据 web 的协议来控制缓存,服务端返回数据的 head 有相关的信息。它可能会返回中间网络媒介(如代理服务器中的数据)
针对缓存策略做一下本地测试,这是非常有必要的
- NSURL *webUrl = [NSURL URLWithString:@"http://localhost/test.txt"];
- NSURLRequest *request =[NSURLRequest requestWithURL:webUrl cachePolicy:NSURLRequestReloadRevalidatingCacheData timeoutInterval:60];
- [self.mainWebView loadRequest:request];
这里使用NSURLRequestReloadRevalidatingCacheData, 返回cache数据一定要先验证数据有效。
- 使用建立两个同名的test.txt, 先放一个到服务器。
- 然后直接修改服务器的 test.txt 文件,添加字段" ----------------------------- " 保存,可以看到马上生效了。
- 用另外一个test.txt替换掉服务器中当前的test.txt,也马上生效了
通过以上简单的验证可以得知NSURLRequestReloadRevalidatingCacheData 这种模式对存储在服务器中的文件的修改和替换是敏感的
我这里使用的是mac系统自带的 appache 服务器
文件目录是在 /Library/WebServer/Documents
启动Apache的方法是在命令行输入 sudo apachectl start
然后输入密码,输入过程命令行是无显示的,不用管,输入之后敲回车键。会有提示:服务器已经启动。
根据文档的信息,initwithURL 使用的默认缓存机制NSURLRequestUseProtocolCachePolicy,并且是60s的请求时间,超过时间会请求失败
相关文件
清除cookie
- NSHTTPCookie *cookie;
- NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
- for (cookie in [storage cookies]) {
- [storage deleteCookie:cookie];
- }
UIWebView的缓存策略,清除cookie的更多相关文章
- uiwebview 清缓存。,mark
//清除cookies NSHTTPCookie *cookie; NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCook ...
- Redis的缓存策略和主键失效机制
作为缓存系统都要定期清理无效数据,就需要一个主键失效和淘汰策略. >>EXPIRE主键失效机制 在Redis当中,有生存期的key被称为volatile,在创建缓存时,要为给定的key设置 ...
- Web开发基本准则-55实录-缓存策略
续上篇<Web开发基本准则-55实录-Web访问安全>. Web开发基本准则-55实录-缓存策略 郑昀 创建于2013年2月 郑昀 最后更新于2013年10月26日 提纲: Web访问安全 ...
- ASP.NET缓存策略经验谈
要提升ASP.NET应用程序的性能,最简单.最有效的方式就是使用内建的缓存引擎.虽然也能构建自己的缓存,但由于缓存引擎已提供了如此多的功能,所以完全不必如此麻烦.在很大程度上,ASP.NET开发者在W ...
- spring aop + xmemcached 配置service层缓存策略
Memcached 作用与使用 基本介绍 1,对于缓存的存取方式,简言之,就是以键值对的形式将数据保存在内存中.在日常业务中涉及的操作无非就是增删改查.加入缓存机制后,查询的时候,对数据进行缓存,增删 ...
- 【安卓中的缓存策略系列】安卓缓存策略之磁盘缓存DiskLruCache
安卓中的缓存包括两种情况即内存缓存与磁盘缓存,其中内存缓存主要是使用LruCache这个类,其中内存缓存我在[安卓中的缓存策略系列]安卓缓存策略之内存缓存LruCache中已经进行过详细讲解,如看官还 ...
- web缓存策略之HTTP缓存大全
一. web缓存总分类 数据库数据缓存 Web应用,特别是SNS类型的应用,往往关系比较复杂,数据库表繁多,如果频繁进行数据库查询,很容易导致数据库不堪重荷.为了提供查询的性能,会将查询后的数据放到内 ...
- nginx静态资源缓存策略配置
1. 问题-背景 以前也经常用nginx,但用的不深,通常是简单的设置个location用来做反向代理.直到今天给客户做项目碰到缓存问题:客户有个app,只是用原生做了个壳,里面的内容都是用h5写的, ...
- ASIHTTPRequest缓存策略download cache
本文为大家介绍了iOS开发ASIHTTPRequest使用download cache的内容,其中包括cache策略,存储策略,其他cache相关的特性,编写自己的cache等等内容. 从1.8版本开 ...
随机推荐
- node服务器获取form表单
搭建好服务器后 (前言,本文只是介绍form表单直接提供给 本页面数据,即在不刷新页面的前提下更改数据) 在public里面添加index.html <!DOCTYPE html> < ...
- 5.4.1 Selenium2启动空浏览器
在Web自动化测试中,必须考虑不同浏览器对网站的兼容性测试,所以我们首先介绍如何用webDriver代码打开不同的浏览器. 本节介绍的是在Selenium2启动浏览器时,启动一个干净的没有任务插件及c ...
- Disable SELinux CentOS 7
Disable SELinux CentOS 7 This blog covers the basic steps to disable SELinux on CentOS 7 first we ne ...
- HTML5自学笔记[ 24 ]canvas绘图之星空草地
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- discuz核心函数库function_core的函数注释
/** * 系统错误处理 * @param <type> $message 错误信息 * @param <type> $show 是否显示信息 * @param <typ ...
- Git从远程分支创建本地分支
git fetch origin master:temp 这句命令的意思是:将远程origin仓库的master分支下载到本地,并新建一个分支temp.
- Pinyin4Net
.net使用的汉字转拼音库.Pinyin4Net 是直接从 Pinyin4J 翻译过来的,很多代码甚至是直接copy的. 用法与pinyin4j完全相同,具体请查阅pinyin4j文档. —— 查看更 ...
- Response返回JSON数据到前台页面
转自博文:<Response JSON数据返回>http://blog.csdn.net/anialy/article/details/8665471 简述: 在servlet填充Resp ...
- wordpress+php+mysql 配置
下载并解压wordpress之后,在mysql新建一个数据库,命名,例如testDB1,然后在IIS中新建虚拟目录,指向wordress所在的目录,删除wordpress目录下的wp-config.p ...
- Excel 函数记录
1.四舍五入:round(数据,小数位数)