【问题标题】:Disk Cache Not Working properly iOS磁盘缓存无法正常工作 iOS
【发布时间】:2015-07-27 06:04:01
【问题描述】:

我已经在我的 AppDelegate 中实现了 NSURLCache

 NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:500*1024*1024 diskCapacity:300 * 1024 * 1024 diskPath:nil];
    [NSURLCache setSharedURLCache:URLCache];

然后我像这样设置和获取缓存图像

UIImage *cachedImage = [[UIImageView sharedImageCache] cachedImageForRequest:urlRequest];
    [[UIImageView sharedImageCache] cacheImage:responseObject forRequest:urlRequest];

但每次我运行应用程序时,所有图像都是从源中获取的。

我在这里做错了吗?

【问题讨论】:

    标签: ios afnetworking


    【解决方案1】:

    如果响应对象大于内存缓存容量的 5%,NSURLCache 将不起作用。因此,在您的情况下,我建议您检查解压缩后的响应是否不大于 ~26 MB。

    除此之外,请确保服务器设置允许缓存的正确标头。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-24
      • 2017-01-29
      • 2019-09-01
      • 2013-03-04
      相关资源
      最近更新 更多