// 清除已過時圖片 [[SDImageCache sharedImageCache] cleanDisk]; // 設置最多緩存7天時間 [[SDImageCache sharedImageCache] setMaxCacheAge:7 * 24 * 60 * 60]; // 設置磁盤最多緩存20M [[SDImageCache sharedImageCache] setMaxCacheSize:20 * 1024 * 1024]; // 內存最多緩存10張100x100像素的圖片(可根據狀況本身調整) [[SDImageCache sharedImageCache] setMaxMemoryCost:10 * 100 * 100]; [[SDImageCache sharedImageCache] setShouldDecompressImages:NO]; [[SDWebImageDownloader sharedDownloader] setShouldDecompressImages:NO];
內存警告時,清除SDWebImage緩存的圖片緩存
// 清空緩存(內存) [[SDImageCache sharedImageCache] clearMemory]; // 清空已過時圖片 [[SDImageCache sharedImageCache] cleanDisk]; // 清空磁盤圖片 [[SDImageCache sharedImageCache] clearDisk];