SDImageCacheConfig.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import "SDImageCacheConfig.h"
  9. #import "SDMemoryCache.h"
  10. #import "SDDiskCache.h"
  11. static SDImageCacheConfig *_defaultCacheConfig;
  12. static const NSInteger kDefaultCacheMaxDiskAge = 60 * 60 * 24 * 7; // 1 week
  13. @implementation SDImageCacheConfig
  14. + (SDImageCacheConfig *)defaultCacheConfig {
  15. static dispatch_once_t onceToken;
  16. dispatch_once(&onceToken, ^{
  17. _defaultCacheConfig = [SDImageCacheConfig new];
  18. });
  19. return _defaultCacheConfig;
  20. }
  21. - (instancetype)init {
  22. if (self = [super init]) {
  23. _shouldDisableiCloud = YES;
  24. _shouldCacheImagesInMemory = YES;
  25. _shouldUseWeakMemoryCache = NO;
  26. _shouldRemoveExpiredDataWhenEnterBackground = YES;
  27. _shouldRemoveExpiredDataWhenTerminate = YES;
  28. _diskCacheReadingOptions = 0;
  29. _diskCacheWritingOptions = NSDataWritingAtomic;
  30. _maxDiskAge = kDefaultCacheMaxDiskAge;
  31. _maxDiskSize = 0;
  32. _diskCacheExpireType = SDImageCacheConfigExpireTypeModificationDate;
  33. _memoryCacheClass = [SDMemoryCache class];
  34. _diskCacheClass = [SDDiskCache class];
  35. }
  36. return self;
  37. }
  38. - (id)copyWithZone:(NSZone *)zone {
  39. SDImageCacheConfig *config = [[[self class] allocWithZone:zone] init];
  40. config.shouldDisableiCloud = self.shouldDisableiCloud;
  41. config.shouldCacheImagesInMemory = self.shouldCacheImagesInMemory;
  42. config.shouldUseWeakMemoryCache = self.shouldUseWeakMemoryCache;
  43. config.shouldRemoveExpiredDataWhenEnterBackground = self.shouldRemoveExpiredDataWhenEnterBackground;
  44. config.shouldRemoveExpiredDataWhenTerminate = self.shouldRemoveExpiredDataWhenTerminate;
  45. config.diskCacheReadingOptions = self.diskCacheReadingOptions;
  46. config.diskCacheWritingOptions = self.diskCacheWritingOptions;
  47. config.maxDiskAge = self.maxDiskAge;
  48. config.maxDiskSize = self.maxDiskSize;
  49. config.maxMemoryCost = self.maxMemoryCost;
  50. config.maxMemoryCount = self.maxMemoryCount;
  51. config.diskCacheExpireType = self.diskCacheExpireType;
  52. config.fileManager = self.fileManager; // NSFileManager does not conform to NSCopying, just pass the reference
  53. config.memoryCacheClass = self.memoryCacheClass;
  54. config.diskCacheClass = self.diskCacheClass;
  55. return config;
  56. }
  57. @end