[英]SDWebImage - avoid clearing image cache on entering background
我在我的應用程序中使用SDWebImage
來加載和緩存來自Web的圖像。 它就像一個魅力,但唯一的問題是每當我退出我的應用程序時,即使是暫時的,圖像緩存也會被清除,所有圖像都必須再次下載。 當Internet連接緩慢時,這尤其成問題。 我想在返回應用程序時保留圖像。 有誰知道如何實現這一目標?
轉到SDImageCache.m並查找方法 - (id)initWithNamespace:(NSString *)ns在那里你會找到這樣的代碼:
// Subscribe to app events
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(clearMemory)
name:UIApplicationDidReceiveMemoryWarningNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(cleanDisk)
name:UIApplicationWillTerminateNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(backgroundCleanDisk)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
如果您願意,可以隨意評論或更改任何內容。 我會選擇關閉這些代碼行。
確保你沒有設置[SDImageCache sharedImageCache]
的maxCacheSize
,如果在應用程序轉到后台時設置它,它將清除緩存文件以適應maxCacheSize
。
在cleanDisk
方法中,您可以看到在刪除文件之前進行檢查
if (self.maxCacheSize > 0 && currentCacheSize > self.maxCacheSize)
{
// ...
}
所以如果沒有設置maxCacheSize
,它將什么都不做。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.