SDImageCacheConfig.m 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 = YES;
  26. _shouldRemoveExpiredDataWhenEnterBackground = YES;
  27. _diskCacheReadingOptions = 0;
  28. _diskCacheWritingOptions = NSDataWritingAtomic;
  29. _maxDiskAge = kDefaultCacheMaxDiskAge;
  30. _maxDiskSize = 0;
  31. _diskCacheExpireType = SDImageCacheConfigExpireTypeModificationDate;
  32. _memoryCacheClass = [SDMemoryCache class];
  33. _diskCacheClass = [SDDiskCache class];
  34. }
  35. return self;
  36. }
  37. - (id)copyWithZone:(NSZone *)zone {
  38. SDImageCacheConfig *config = [[[self class] allocWithZone:zone] init];
  39. config.shouldDisableiCloud = self.shouldDisableiCloud;
  40. config.shouldCacheImagesInMemory = self.shouldCacheImagesInMemory;
  41. config.shouldUseWeakMemoryCache = self.shouldUseWeakMemoryCache;
  42. config.shouldRemoveExpiredDataWhenEnterBackground = self.shouldRemoveExpiredDataWhenEnterBackground;
  43. config.diskCacheReadingOptions = self.diskCacheReadingOptions;
  44. config.diskCacheWritingOptions = self.diskCacheWritingOptions;
  45. config.maxDiskAge = self.maxDiskAge;
  46. config.maxDiskSize = self.maxDiskSize;
  47. config.maxMemoryCost = self.maxMemoryCost;
  48. config.maxMemoryCount = self.maxMemoryCount;
  49. config.diskCacheExpireType = self.diskCacheExpireType;
  50. config.fileManager = self.fileManager; // NSFileManager does not conform to NSCopying, just pass the reference
  51. config.memoryCacheClass = self.memoryCacheClass;
  52. config.diskCacheClass = self.diskCacheClass;
  53. return config;
  54. }
  55. @end