zoukankan      html  css  js  c++  java
  • 网络编程练习 -- NSURLCache

    LWTViewController.m

    //
    //  LWTViewController.m
    //  网络编程练习 -- NSURLCache
    //
    //  Created by apple on 14-7-2.
    //  Copyright (c) 2014年 lwt. All rights reserved.
    //
    
    #import "LWTViewController.h"
    
    @interface LWTViewController ()
    
    @end
    
    @implementation LWTViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        NSURL *url = [NSURL URLWithString:@"http://192.168.1.24:8080/MJServer/resources/video"];
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
        
        NSURLCache *cache = [NSURLCache sharedURLCache];
        cache.memoryCapacity = 1024 * 1024;
        cache.diskCapacity = 10 * 1024 * 1024;
        request.cachePolicy = NSURLRequestReturnCacheDataElseLoad;
        
        NSCachedURLResponse *response = [cache cachedResponseForRequest:request];
        if (response) {
            NSLog(@"---这个请求已经存在缓存");
        } else {
            NSLog(@"---这个请求没有缓存");
        }
        
        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            NSLog(@"%@",dict);
        }];
        
        
    }
    
    @end
    View Code
  • 相关阅读:
    ExtJS学习之路第一步:对比jQuery,认识ExtJS
    创建Windows服务(C++)
    吴恩达2014机器学习教程笔记目录
    在Hexo中渲染MathJax数学公式
    Linux服务器性能检测命令集锦
    Redis开启AOF导致的删库事件
    从表扩展增加列属性说起
    数据库规约解读
    MySQL规约(阿里巴巴)
    HDFS运行原理
  • 原文地址:https://www.cnblogs.com/wentianblog/p/3820778.html
Copyright © 2011-2022 走看看