Browse Source

merge from YYImage and YYCache

ibireme 9 years ago
parent
commit
1903f39d96
3 changed files with 17 additions and 9 deletions
  1. 8 3
      YYWebImage/Cache/YYCache.m
  2. 8 5
      YYWebImage/Cache/YYKVStorage.m
  3. 1 1
      YYWebImage/Image/YYImageCoder.m

+ 8 - 3
YYWebImage/Cache/YYCache.m

@@ -43,11 +43,11 @@
 }
 
 + (instancetype)cacheWithName:(NSString *)name {
-	return [[YYCache alloc] initWithName:name];
+    return [[self alloc] initWithName:name];
 }
 
 + (instancetype)cacheWithPath:(NSString *)path {
-    return [[YYCache alloc] initWithPath:path];
+    return [[self alloc] initWithPath:path];
 }
 
 - (BOOL)containsObjectForKey:(NSString *)key {
@@ -85,7 +85,12 @@
             block(key, object);
         });
     } else {
-        [_diskCache objectForKey:key withBlock:block];
+        [_diskCache objectForKey:key withBlock:^(NSString *key, id<NSCoding> object) {
+            if (object && ![_memoryCache objectForKey:key]) {
+                [_memoryCache setObject:object forKey:key];
+            }
+            block(key, object);
+        }];
     }
 }
 

+ 8 - 5
YYWebImage/Cache/YYKVStorage.m

@@ -554,11 +554,14 @@ static UIApplication *_YYSharedApplication() {
             char *key = (char *)sqlite3_column_text(stmt, 0);
             char *filename = (char *)sqlite3_column_text(stmt, 1);
             int size = sqlite3_column_int(stmt, 2);
-            YYKVStorageItem *item = [YYKVStorageItem new];
-            item.key = key ? [NSString stringWithUTF8String:key] : nil;
-            item.filename = filename ? [NSString stringWithUTF8String:filename] : nil;
-            item.size = size;
-            [items addObject:item];
+            NSString *keyStr = key ? [NSString stringWithUTF8String:key] : nil;
+            if (keyStr) {
+                YYKVStorageItem *item = [YYKVStorageItem new];
+                item.key = key ? [NSString stringWithUTF8String:key] : nil;
+                item.filename = filename ? [NSString stringWithUTF8String:filename] : nil;
+                item.size = size;
+                [items addObject:item];
+            }
         } else if (result == SQLITE_DONE) {
             break;
         } else {

+ 1 - 1
YYWebImage/Image/YYImageCoder.m

@@ -2783,7 +2783,7 @@ CGImageRef YYCGImageCreateWithWebPData(CFDataRef webpData,
 }
 
 - (BOOL)yy_isDecodedForDisplay {
-    if (self.images.count > 1) return YES;
+    if (self.images.count > 1 || [self isKindOfClass:[YYSpriteSheetImage class]]) return YES;
     NSNumber *num = objc_getAssociatedObject(self, @selector(yy_isDecodedForDisplay));
     return [num boolValue];
 }