diff --git a/SDWebImage/SDMemoryCache.m b/SDWebImage/SDMemoryCache.m index e434f4ec..45759650 100644 --- a/SDWebImage/SDMemoryCache.m +++ b/SDWebImage/SDMemoryCache.m @@ -84,6 +84,9 @@ static void * SDMemoryCacheContext = &SDMemoryCacheContext; // `setObject:forKey:` just call this with 0 cost. Override this is enough - (void)setObject:(id)obj forKey:(id)key cost:(NSUInteger)g { [super setObject:obj forKey:key cost:g]; + if (!self.config.shouldUseWeakMemoryCache) { + return; + } if (key && obj) { // Store weak cache LOCK(self.weakCacheLock); @@ -94,6 +97,9 @@ static void * SDMemoryCacheContext = &SDMemoryCacheContext; - (id)objectForKey:(id)key { id obj = [super objectForKey:key]; + if (!self.config.shouldUseWeakMemoryCache) { + return obj; + } if (key && !obj) { // Check weak cache LOCK(self.weakCacheLock); @@ -113,6 +119,9 @@ static void * SDMemoryCacheContext = &SDMemoryCacheContext; - (void)removeObjectForKey:(id)key { [super removeObjectForKey:key]; + if (!self.config.shouldUseWeakMemoryCache) { + return; + } if (key) { // Remove weak cache LOCK(self.weakCacheLock); @@ -123,6 +132,9 @@ static void * SDMemoryCacheContext = &SDMemoryCacheContext; - (void)removeAllObjects { [super removeAllObjects]; + if (!self.config.shouldUseWeakMemoryCache) { + return; + } // Manually remove should also remove weak cache LOCK(self.weakCacheLock); [self.weakCache removeAllObjects];