From 9afbc8bf7eb8799e7920d44e9a9e5614f9d10ae9 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Fri, 24 Aug 2018 15:54:04 +0800 Subject: [PATCH] Add no expiration file support of disk cache --- SDWebImage/SDDiskCache.m | 4 ++-- SDWebImage/SDImageCacheConfig.h | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) 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;