• 网络编程练习 -- 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
  • 相关阅读:
    kubeadm快捷k8s集群
    常用my.cnf
    cka考试 列出命名空间下指定标签pod
    mysql 巡检项
    1、什么原因可能导致主从同步延时,怎么判断,怎么处理?
    Linux运维常用操作培训用例
    RMAN 还原与恢复
    常见网络故障及其维修方法
    Oracle ORA01654 解决方案
    Oracle中 dba_* 和 v$* 表区别
  • 原文地址:https://www.cnblogs.com/wentianblog/p/3820778.html
Copyright © 2020-2023  润新知