使用AFNetworking的setImageWithURL时如何配置缓存 [英] How to configure the cache when using AFNetworking's setImageWithURL

查看:119
本文介绍了使用AFNetworking的setImageWithURL时如何配置缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 setImageWithURL 在我的应用中下载一些图片。是否有可能:

I'm using setImageWithURL to download some images in my app. Is it possible:


  1. 指定此图像必须在缓存中保留多长时间(例如1周)?

  2. 指定缓存的最大总大小有多大(例如200
    MB)

  3. 以查看图像缓存中的内容?

  4. 清除缓存?

  1. to specify how long this image must be held in cache (eg 1 week)?
  2. to specify how big the the maximum total size of the cache (eg 200 MB)
  3. to see what is in the image cache?
  4. to clear the cache?

文档在这些方面并不是很清楚..

The documentation is not really clear on these points..

推荐答案

UIImageView 类别使用内部短暂缓存在 UITableView 等内容中实现高性能。对于长期缓存,请使用系统级缓存系统 - 即Peter Steinberger的 SDURLCache 的分支, NSURLCache

The UIImageView category uses an internal, ephemeral cache for high performance in things like UITableView. For longer-term cache, use the system-level cacheing system--namely Peter Steinberger's fork of SDURLCache, a subclass of NSURLCache.

使用应用程序委托中的以下代码进行设置 applicationDidFinishLaunching:withOptions:

Set it up with the following code in the application delegate applicationDidFinishLaunching:withOptions::

SDURLCache *URLCache = [[SDURLCache alloc] initWithMemoryCapacity:1024*1024*2 diskCapacity:1024*1024*20 diskPath:[SDURLCache defaultCachePath]];
[URLCache setIgnoreMemoryOnlyStoragePolicy:YES];
[NSURLCache setSharedURLCache:URLCache];
[URLCache release];

这篇关于使用AFNetworking的setImageWithURL时如何配置缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆