Ios 为什么SDWebImage在NSCache上使用锁?

Ios 为什么SDWebImage在NSCache上使用锁?,ios,objective-c,nscache,Ios,Objective C,Nscache,文件中 苹果说 您可以从不同位置添加、删除和查询缓存中的项 线程,而不必自己锁定缓存 简而言之,它们不在NSCache上使用LOCK。他们的缓存实现 它们有多种不同类型的缓存,只有一种包在锁/解锁中的缓存是weakCache: @property (nonatomic, strong, nonnull) NSMapTable<KeyType, ObjectType> *weakCache; // strong-weak cache // `setObject:forKey:` ju

文件中 苹果说

您可以从不同位置添加、删除和查询缓存中的项 线程,而不必自己锁定缓存


简而言之,它们不在
NSCache
上使用
LOCK
。他们的缓存实现

它们有多种不同类型的缓存,只有一种包在锁/解锁中的缓存是
weakCache

@property (nonatomic, strong, nonnull) NSMapTable<KeyType, ObjectType> *weakCache; // strong-weak cache
// `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);
        [self.weakCache setObject:obj forKey:key];
        UNLOCK(self.weakCacheLock);
    }
}