关于NSCache的使用

来源:互联网 发布:淘宝优惠券pc转无线 编辑:程序博客网 时间:2024/05/06 21:03

1. NSCache 和 NSMutableDictionary 比较

用法基本类似只是NSCache 并没有像字典那样的操作

   [self.imageCache setObject:image forKey:URLStr];


2. 当对 NSCache  removeAllObject 之后会出现无法再次赋值的问题

解决办法 

运用 dispatch_once 方法延迟一秒执行清理操作即可


-(void)clearMemoryCache   dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{     [self.imageCache removeAllObjects];    
});
}




1 0
原创粉丝点击