使用AFNetworking的setImageWithURL时如何配置缓存

mur*_*rze 3 caching objective-c ios5 afnetworking

我正在使用setImageWithURL我的应用程序下载一些图像.可能吗:

  1. 指定此图像必须在缓存中保留多长时间(例如1周)?
  2. 指定缓存的最大总大小有多大(例如200 MB)
  3. 看看图像缓存中有什么?
  4. 清除缓存?

关于这些问题,文件并不是很清楚.

mat*_*ttt 13

UIImageView类别使用内部短暂缓存来实现高性能UITableView.对于长期缓存,请使用系统级缓存系统 - 即Peter Steinberger的fork SDURLCache,它的子类NSURLCache.

使用应用程序委托中的以下代码进行设置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];
Run Code Online (Sandbox Code Playgroud)

  • @MadNik`NSURLRequest`对象有一个`cachePolicy`属性,您可以相应地设置它. (2认同)