使用SDWebImage的時候,從服務器請求回來的頭像URL沒有變化,但是用戶已經修改過頭像,由于緩存的原因,不能顯示出最新修改的用戶的頭像。在不去掉緩存的條件下,如何顯示出最新的頭像,給出以下方法。
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
然后option選擇??? SDWebImageRefreshCached。
/**
* Set the imageView `image` with an `url`, placeholder and custom options.【用url設置圖片,占位圖以及自定義選項】
*
* The download is asynchronous and cached.【下載和緩存都是異步執行】
*
* @param url? ? ? ? The url for the image.【url獲取imge】
* @param placeholder The image to be set initially, until the image request finishes.【占位圖先顯示,知道數據請求成功后消失】
* @param options? ? The options to use when downloading the image. @see SDWebImageOptions for the possible values.
*/
法2:url加上時間戳
一旦用戶的頭像資料修改后,需要把最新的頭像和時間戳發給服務器。同時更新數據,從服務端獲取過來,然后展示獲取的數據(包括頭像,頭像加上時間戳),這樣,每次的url都不一樣。