Skip to content

Commit

Permalink
修复 d10a433 的bug,可能总是从diskcache取图片
Browse files Browse the repository at this point in the history
  • Loading branch information
cddjr committed May 18, 2018
1 parent a0ae4ea commit 75ce6c6
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions YYWebImage/YYWebImageOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -331,26 +331,19 @@ - (void)_startOperation {
!(_options & YYWebImageOptionRefreshImageCache)) {

UIImage *image = nil;

//尝试从Disk里面提取
//Try to extract oil from the Disk
if (!(_options & YYWebImageOptionIgnoreDiskCache) &&
_transform && _transformCacheKey) {
//前面为了快速显示图片,只是从内存里面尝试提取图片
//Front to display images quickly, just try to extract oil from the memory images
image = [_cache getImageForKey:_transformCacheKey withType:YYImageCacheTypeDisk];
}

if (image == nil) {
image = [_cache getImageForKey:_cacheKey withType:YYImageCacheTypeMemory];

if (_transform && image && _transformCacheKey) {
image = _transform(image, _request.URL);
[_cache setImage:image forKey:_transformCacheKey];
if (_transform && _transformCacheKey) {
image = [_cache getImageForKey:_transformCacheKey withType:YYImageCacheTypeMemory];
if (image == nil) {
image = [_cache getImageForKey:_cacheKey withType:YYImageCacheTypeMemory];
if (image) {
image = _transform(image, _request.URL);
[_cache setImage:image imageData:nil forKey:_transformCacheKey withType:YYImageCacheTypeMemory];
}
}
} else {
image = [_cache getImageForKey:_cacheKey withType:YYImageCacheTypeMemory];
}


if (image) {
[_lock lock];
if (![self isCancelled]) {
Expand All @@ -366,15 +359,24 @@ - (void)_startOperation {
dispatch_async([self.class _imageQueue], ^{
__strong typeof(_self) self = _self;
if (!self || [self isCancelled]) return;
UIImage *image = [self.cache getImageForKey:self.cacheKey withType:YYImageCacheTypeDisk];

if (_transform && image && _transformCacheKey) {
image = _transform(image, _request.URL);
[_cache setImage:image forKey:_transformCacheKey];
UIImage *image = nil;
if (_transform && _transformCacheKey) {
image = [_cache getImageForKey:_transformCacheKey withType:YYImageCacheTypeDisk];
if (image == nil) {
image = [_cache getImageForKey:_cacheKey withType:YYImageCacheTypeDisk];
if (image) {
image = _transform(image, _request.URL);
[_cache setImage:image forKey:_transformCacheKey];
}
} else {
[_cache setImage:image imageData:nil forKey:_transformCacheKey withType:YYImageCacheTypeMemory];
}
} else {
image = [_cache getImageForKey:_cacheKey withType:YYImageCacheTypeDisk];
}

if (image) {
if (!(_transform && image && _transformCacheKey)) {
if (!(_transform && _transformCacheKey)) {
[self.cache setImage:image imageData:nil forKey:self.cacheKey withType:YYImageCacheTypeMemory];
}

Expand Down

0 comments on commit 75ce6c6

Please sign in to comment.