Sdwebimage and Nscache of multi-threading and network

Source: Internet
Author: User
Tags base64

Sdwebimage
  • Basic use of 1.SDWebImage

    01 setting ImageView's Picture [Cell.imageview Sd_setimagewithurl:[nsurl URLWithString:app.icon] Placeholderimage:[uiimage imagenamed:@ "Placehoder"]];//02 set picture and calculate download progress//download and set picture/* First parameter: The URL address of the image to download the second parameter: set the placeholder picture for the ImageView The third argument: pass an enumeration value, Tell the program what your strategy for downloading the picture is. The first block block: Gets the download progress of the current picture data receivedsize: The size of the data that has been downloaded Expectedsize: The total data size of the file the second block chunk: Executes the bloc after the picture is downloaded Code in K Image: Download the resulting image data error: Download errors message sdimagecachetype: Image cache Policy (no cache, memory cache, sandbox cache) ImageURL: URL address of downloaded picture */[cell . ImageView Sd_setimagewithurl:[nsurl URLWithString:app.icon] placeholderimage:[uiimage imagenamed:@ "Placehoder"] o Ptions:sdwebimageretryfailed progress:^ (Nsinteger receivedsize, Nsinteger expectedsize) {//Calculate the current picture's download Progress NSLog (@ "%.2f ", 1.0 *receivedsize/expectedsize);} completed:^ (UIImage *image, Nserror *error, Sdimagecachetype cachetype, Nsurl *imageurl) {}];//03 system-level memory warning how to handle (interview)//Use Notifications    Center Watch (Monitoring system warning)-Uiapplicationdidreceivememorywarningnotification receive a memory warning notification execute Clearmemory method to clean up the memory cache! -UIAPPLICATIONWILlterminatenotification receiving application will terminate notification execution Cleandisk method, clean disk cache! (according to the file creation Order: from far to near) first delete the past cache, calculate the size of the current cache maxcachesize set the size of the cache, the default is 0 is greater than the set cache size, if exceeded, continue to delete until less than- Uiapplicationdidenterbackgroundnotification receive application into background notification execution Backgroundcleandisk method, background cleanup disk! Through the above exit notification, can ensure that the size of the cache file is always within the control range! Cleardisk empty the disk cache, delete all the files in the cache directory! Actually work, delete the cache directory directly, create an empty directory with the same name again! Sdwebimage The default cache time is: 1 weeks sdwebimage memory cache is implemented with what: the maximum concurrency of NSCache06 sdwebimag is: maxconcurrentdownloads = 6 is the program fixed dead, Properties can be adjusted 07 how to play a GIF picture/*5-1 a user-passed GIF image->nsdata5-2 create a picture data source based on that data (NSDATA->CFIMAGESOURCEREF) 5-3 Calculate the total number of frames in the data source, take each frame of data out to the image array 5-4 according to the resulting array + calculated animation Time-"animated Image[uiimage animatedimagewithimages:images Duration: Duration];*/08 how to determine the current picture type + (NSString *) Sd_contenttypeforimagedata: (NSData *) data;09 sdwebimage is how to distinguish different formats of images based on the image data        To judge by a byte!        PNG: Compression ratio without JPG high, but lossless compression, high decompression performance, Apple recommended image format! JPG: Compression ratio of the highest image format, lossy compression, compression performance is not good! Most used scenes, camera GIF: Sequence frame motion diagram, features: Only 256 colors are supported! Most popular time in 1998~1999, patented 10 Picture Download order (FIFO | fifo) default is FIFO
Nscache
2.NSCache知识点补充 01.NSCache是专门用来进行缓存处理的, 02.NSCache简单介绍:    2-1 NSCache是苹果官方提供的缓存类,具体使用和NSDictionary类似,在AFN和SDWebImage框架中被使用来管理缓存    2-2 苹果官方解释NSCache在系统内存很低时,会自动释放对象(但模拟器演示不会释放)        建议:接收到内存警告时主动调用removeAllObject方法释放对象    2-3 NSCache是线程安全的,在多线程操作中,不需要对NSCache加锁    2-4 NSCache的Key只是对对象进行Strong引用,不是拷贝 03 属性介绍:    name:名称    delegete:设置代理    totalCostLimit:缓存空间的最大总成本,超出上限会自动回收对象。默认值为0,表示没有限制    countLimit:能够缓存的对象的最大数量。默认值为0,表示没有限制    evictsObjectsWithDiscardedContent:标识缓存是否回收废弃的内容 04 方法介绍- (void)setObject:(ObjectType)obj forKey:(KeyType)key; //在缓存中设置指定键名对应的值,0成本- (void)setObject:(ObjectType)obj forKey:(KeyType)key cost:(NSUInteger)g; //在缓存中设置指定键名对应的值,    并且指定该键值对的成本,用于计算记录在缓存中的所有对象的总成本,出现内存警告或者超出缓存总成本上限    的时候,缓存会开启一个回收过程,删除部分元素- (void)removeObjectForKey:(KeyType)key; //删除缓存中指定键名的对象- (void)removeAllObjects; //删除缓存中所有的对象

Sdwebimage and Nscache of multi-threading and network

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.