• iOS缓存


    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        // 1.创建请求
        NSURL *url = [NSURL URLWithString:@"http://127.0.0.1:8080/YYServer/video"];
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
        
        // 2.设置缓存策略(有缓存就用缓存,没有缓存就重新请求)
        request.cachePolicy = NSURLRequestReturnCacheDataElseLoad;
        
        // 3.发送请求
        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            if (data) {
                NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
                
                NSLog(@"%@", dict);
            }
        }];
    }
    
    /**
     // 定期处理缓存
     //    if (缓存没有达到7天) {
     //        request.cachePolicy = NSURLRequestReturnCacheDataElseLoad;
     //    }
     // 获得全局的缓存对象
     NSURLCache *cache = [NSURLCache sharedURLCache];
     //    if (缓存达到7天) {
     //        [cache removeCachedResponseForRequest:request];
     //    }
     
     // lastCacheDate = 2014-06-30 11:04:30
     
     NSCachedURLResponse *response = [cache cachedResponseForRequest:request];
     if (response) {
     NSLog(@"---这个请求已经存在缓存");
     } else {
     NSLog(@"---这个请求没有缓存");
     }
     */
  • 相关阅读:
    210
    209
    208
    207
    定时任务crontab
    Python的zip与*zip函数的应用
    Python的reduce函数与map函数
    解析:cpu与io密集在何场景适合使用多进程,多线程,协程
    Python上下文(转载)
    C10K与C10M的问题
  • 原文地址:https://www.cnblogs.com/hualuoshuijia/p/5703089.html
Copyright © 2020-2023  润新知