diff --git a/SDWebImage/SDDiskCache.m b/SDWebImage/SDDiskCache.m index 539cd68b..bcad109d 100644 --- a/SDWebImage/SDDiskCache.m +++ b/SDWebImage/SDDiskCache.m @@ -135,7 +135,7 @@ options:NSDirectoryEnumerationSkipsHiddenFiles errorHandler:NULL]; - NSDate *expirationDate = [NSDate dateWithTimeIntervalSinceNow:-self.config.maxCacheAge]; + NSDate *expirationDate = (self.config.maxCacheAge < 0) ? nil: [NSDate dateWithTimeIntervalSinceNow:-self.config.maxCacheAge]; NSMutableDictionary *> *cacheFiles = [NSMutableDictionary dictionary]; NSUInteger currentCacheSize = 0; @@ -155,7 +155,7 @@ // Remove files that are older than the expiration date; NSDate *modifiedDate = resourceValues[cacheContentDateKey]; - if ([[modifiedDate laterDate:expirationDate] isEqualToDate:expirationDate]) { + if (expirationDate && [[modifiedDate laterDate:expirationDate] isEqualToDate:expirationDate]) { [urlsToDelete addObject:fileURL]; continue; } diff --git a/SDWebImage/SDImageCacheConfig.h b/SDWebImage/SDImageCacheConfig.h index 3ac6fc7c..8732eaec 100644 --- a/SDWebImage/SDImageCacheConfig.h +++ b/SDWebImage/SDImageCacheConfig.h @@ -68,13 +68,14 @@ typedef NS_ENUM(NSUInteger, SDImageCacheConfigExpireType) { @property (assign, nonatomic) NSDataWritingOptions diskCacheWritingOptions; /** - * The maximum length of time to keep an image in the cache, in seconds. + * The maximum length of time to keep an image in the disk cache, in seconds. + * Setting this to a negative value means no expiring. * Defaults to 1 weak. */ @property (assign, nonatomic) NSTimeInterval maxCacheAge; /** - * The maximum size of the cache, in bytes. + * The maximum size of the disk cache, in bytes. * Defaults to 0. Which means there is no cache size limit. */ @property (assign, nonatomic) NSUInteger maxCacheSize;