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版本开 ...
随机推荐
- python3.x随手笔记2
对象,价值观和类型 对象 Python的抽象的数据. 所有的数据在一个Python程序 表示对象或对象之间的关系. (在某种意义上,在 符合冯诺依曼模型的代码也“存储程序计算机” 由对象.) 每一个对 ...
- sublime text修改TAB缩进为2个空格
打开sublime后在倒数第二项 preference---->Settings-user: 然后输入 "tab_size": 2, "translate_tabs ...
- Flask中mongodb实现flask_login保持登录
最近在学习Flask,使用flask-login时,一直无法完成保持登录的状态,网上的例子都是使用SQLAlchemy,但是我用的是mongodb. 网上的例子使用SQLAlchemy时,定义User ...
- Shell基础:Linux权限管理
Linux权限基本概念 查看系统(文件夹/文件)权限: ls -l =>d/- xxx xxx xxx. num owner group size date filename ...
- BT5更新源
感谢http://blog.csdn.net/seaos/article/details/7064136终于找到更新成功的源了 下面简单介绍步骤吧 gedit /etc/apt/sources.lis ...
- Excepion
异常:就是程序在运行时出现不正常的情况. 异常由来:问题也就是现实生活中一个具体的食物,也可以通过java的类的形式进行秒速.并封装成对象.其实就是java对不正常情况进行毛素后的对象体现. 对于问题 ...
- 网页html结构右侧栏固定,左侧自适应大小。
最近写了一个项目,写页面的结构,html树形结构是有header,container,footer部分,其中container部分是右侧栏是固定宽度,左侧是自适应宽度与屏幕高度. 第一次写的博客文章是 ...
- mongodb的安装及注意事项
环境:win8 32bit 1:安装 去mongodb的官网http://www.mongodb.org/downloads下载32bit的包 解压后会出现以下文件 在安装的盘C:下建立mongodb ...
- thinkjs——空对象判断
使用thinkjs来做后台的项目开发时,总免不了进行一些数据的唯一性校验,比如说:有这么一个页面,需要对钢厂的名称做一个校验,于是自己在后台做条件搜索时,一不小心用到了两种方法: 一个是find(), ...
- cisco nat
1.配置端口: int s0/0 ip nat outside ;s0/0为外部端口 int f0/0 ip nat inside ...