How to configure the cache when using AFNetworking's setImageWithURL

前端 未结 1 1108
野性不改
野性不改 2021-02-03 15:51

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

  1. to specify how long this image must be held in cache (eg 1 week)?
  2. <
相关标签:
1条回答
  • 2021-02-03 16:41

    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.

    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];
    
    0 讨论(0)
提交回复
热议问题