NSURLCache缓存
来源:互联网 发布:雅思托福的区别知乎 编辑:程序博客网 时间:2024/06/06 23:56
#import
@interface ViewController :UIViewController
@property (strong,nonatomic)NSURLConnection*connection;
@property (strong, nonatomic)NSURLCache *urlCache;
@property (strong, nonatomic)NSURL*url;
@property (strong, nonatomic)NSMutableURLRequest *request;
- (IBAction)reloadWebView:(UIButton *)sender;
@end
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad
{
}
这个例子中,我们请求url为http://blog.sina.com.cn/u/2526279194的网站。如果这个url被缓存了,我们直接从缓存中获取数据,否则从http://blog.sina.com.cn/u/2526279194站点上重新获取数据。我们设置了缓存大小为1M。
- (IBAction)reloadWebView:(UIButton *)sender {
}
使用下面代码,我将请求的过程打印出来
- (void)
}
- (NSURLRequest *)connection:(NSURLConnection *)connection
}
- (void)connection:(NSURLConnection *)connection
}
-(NSCachedURLResponse*)connection:(NSURLConnection *)connection
}
- (void)connectionDidFinishLoadi
}
- (void)connection:(NSURLConnection *)connection
}
@end
第一次打印结果如下
2013-01-31 15:28:29.923NSURLCacheDemo[27848:907]即将发送请求
2013-01-31 15:28:30.043NSURLCacheDemo[27848:907]将接收输出
2013-01-31 15:28:30.045NSURLCacheDemo[27848:907]接受数据
2013-01-31 15:28:30.047NSURLCacheDemo[27848:907]数据长度为= 30047
2013-01-31 15:28:30.095NSURLCacheDemo[27848:907]接受数据
2013-01-31 15:28:30.098NSURLCacheDemo[27848:907]数据长度为= 3575
2013-01-31 15:28:30.102NSURLCacheDemo[27848:907]接受数据
2013-01-31 15:28:30.104NSURLCacheDemo[27848:907]数据长度为= 1482
2013-01-31 15:28:30.105NSURLCacheDemo[27848:907]将缓存输出
2013-01-31 15:28:30.107NSURLCacheDemo[27848:907]请求完成
第二次点击打印结果如下
2013-01-31 15:28:31.599NSURLCacheDemo[27848:907]如果有缓存输出,从缓存中获取数据
2013-01-31 15:28:31.607NSURLCacheDemo[27848:907]即将发送请求
2013-01-31 15:28:31.840NSURLCacheDemo[27848:907]将接收输出
2013-01-31 15:28:31.843NSURLCacheDemo[27848:907]接受数据
2013-01-31 15:28:31.845NSURLCacheDemo[27848:907]数据长度为= 35104
2013-01-31 15:28:31.846NSURLCacheDemo[27848:907]请求完成
- NSURLCache缓存
- iOS 缓存 NSURLCache类
- NSURLCache内存缓存
- NSURLCache内存缓存
- NSURLCache内存缓存
- NSURLCache内存缓存
- NSURLCache内存缓存
- 数据缓存NSURLCache
- NSURLCache内存缓存
- NSURLCache内存缓存 (
- NSURLCache 2 内存缓存
- NSURLCache内存缓存
- NSURLCache内存缓存
- NSURLCache 内存缓存
- iOS -NSURLCache内存缓存
- NSURLCache内存缓存
- 系统缓存NSURLCache
- iOS NSURLCache(网络缓存)
- LwIP 协议栈源码详解 ——TCP/IP 协议的实现(七:以太网数据接收)
- iOS的UDID废用以及UUID配合keychain的替换方案实现
- Hadoop入门(1):安装Hadoop
- 菜鸟点滴--error: #130: expected a "{
- Android LayoutInflater - Dynamically Add and Remove Views using Java code
- NSURLCache缓存
- JavaScript trim函数大赏
- 真正理解ASP.NET的ViewState (Truly Understanding ViewState)
- Java联网操作
- iOS 7 之 Sprites
- ociuldr oracle导出数据到txt
- jquery如何获取选中的单选按钮的值
- 读书笔记——COM技术内幕(1)组件
- UML_Activity Diagram