SDImageCachesManager.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 <Foundation/Foundation.h>
  9. #import "SDImageCacheDefine.h"
  10. /// Policy for cache operation
  11. typedef NS_ENUM(NSUInteger, SDImageCachesManagerOperationPolicy) {
  12. SDImageCachesManagerOperationPolicySerial, // process all caches serially (from the highest priority to the lowest priority cache by order)
  13. SDImageCachesManagerOperationPolicyConcurrent, // process all caches concurrently
  14. SDImageCachesManagerOperationPolicyHighestOnly, // process the highest priority cache only
  15. SDImageCachesManagerOperationPolicyLowestOnly // process the lowest priority cache only
  16. };
  17. /**
  18. A caches manager to manage multiple caches.
  19. */
  20. @interface SDImageCachesManager : NSObject <SDImageCache>
  21. /**
  22. Returns the global shared caches manager instance. By default we will set [`SDImageCache.sharedImageCache`] into the caches array.
  23. */
  24. @property (nonatomic, class, readonly, nonnull) SDImageCachesManager *sharedManager;
  25. // These are op policy for cache manager.
  26. /**
  27. Operation policy for query op.
  28. Defaults to `Serial`, means query all caches serially (one completion called then next begin) until one cache query success (`image` != nil).
  29. */
  30. @property (nonatomic, assign) SDImageCachesManagerOperationPolicy queryOperationPolicy;
  31. /**
  32. Operation policy for store op.
  33. Defaults to `HighestOnly`, means store to the highest priority cache only.
  34. */
  35. @property (nonatomic, assign) SDImageCachesManagerOperationPolicy storeOperationPolicy;
  36. /**
  37. Operation policy for remove op.
  38. Defaults to `Concurrent`, means remove all caches concurrently.
  39. */
  40. @property (nonatomic, assign) SDImageCachesManagerOperationPolicy removeOperationPolicy;
  41. /**
  42. Operation policy for contains op.
  43. Defaults to `Serial`, means check all caches serially (one completion called then next begin) until one cache check success (`containsCacheType` != None).
  44. */
  45. @property (nonatomic, assign) SDImageCachesManagerOperationPolicy containsOperationPolicy;
  46. /**
  47. Operation policy for clear op.
  48. Defaults to `Concurrent`, means clear all caches concurrently.
  49. */
  50. @property (nonatomic, assign) SDImageCachesManagerOperationPolicy clearOperationPolicy;
  51. /**
  52. All caches in caches manager. The caches array is a priority queue, which means the later added cache will have the highest priority
  53. */
  54. @property (nonatomic, copy, nullable) NSArray<id<SDImageCache>> *caches;
  55. /**
  56. Add a new cache to the end of caches array. Which has the highest priority.
  57. @param cache cache
  58. */
  59. - (void)addCache:(nonnull id<SDImageCache>)cache;
  60. /**
  61. Remove a cache in the caches array.
  62. @param cache cache
  63. */
  64. - (void)removeCache:(nonnull id<SDImageCache>)cache;
  65. @end