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

编程入门 行业动态 更新时间:2024-10-22 16:36:13
本文介绍了使用AFNetworking的setImageWithURL时如何配置缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

  • 指定此图像必须在缓存中保留多长时间(例如1周)?
  • 指定缓存的最大总大小有多大(例如200 MB)
  • 以查看图像缓存中的内容?
  • 清除缓存?
  • to specify how long this image must be held in cache (eg 1 week)?
  • to specify how big the the maximum total size of the cache (eg 200 MB)
  • to see what is in the image cache?
  • 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时如何配置缓存

    本文发布于:2023-11-26 02:59:32,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1632367.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:缓存   AFNetworking   setImageWithURL

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!