1 // Copyright 2015-present 650 Industries. All rights reserved. 2 3 #import <Foundation/Foundation.h> 4 5 NS_ASSUME_NONNULL_BEGIN 6 7 /** 8 * This is the versioned protocol for EXCachedResource, this also defines some 9 * of the types used when interacting with EXCachedResource instances. This is 10 * used with the EXCachedResourceManager service to be able to create EXCachedResource 11 * instances in versioned code. 12 * 13 * **Avoid making breaking changes to this and if you do make sure to edit all 14 * versions of this file.** 15 */ 16 17 @interface EXLoadingProgress : NSObject 18 19 @property (nonatomic, copy) NSString *status; 20 @property (nonatomic, strong) NSNumber *done; 21 @property (nonatomic, strong) NSNumber *total; 22 23 @end 24 25 typedef void (^EXCachedResourceSuccessBlock)(NSData *data); 26 typedef void (^EXCachedResourceErrorBlock)(NSError *error); 27 typedef void (^EXCachedResourceProgressBlock)(EXLoadingProgress *progress); 28 29 typedef enum EXCachedResourceBehavior { 30 // load the resource without using any cache. 31 EXCachedResourceNoCache, 32 // load the resource without reading from the cache, but still write the loaded resource to the cache. 33 EXCachedResourceWriteToCache, 34 // return immediately with cached data if it exists, then try to download the resource and replace the cache in the background. 35 EXCachedResourceUseCacheImmediately, 36 // return immediately with cached data if it exists, and only try to download the resource if cached data is not found. 37 EXCachedResourceFallBackToNetwork, 38 // try to download the resource, but fall back to the cached version if the download fails. 39 EXCachedResourceFallBackToCache, 40 // use a cache if it exists, otherwise fail. (don't download anything) 41 EXCachedResourceOnlyCache, 42 } EXCachedResourceBehavior; 43 44 @protocol EXResourceLoader 45 46 - (void)loadResourceWithBehavior:(EXCachedResourceBehavior)behavior 47 progressBlock:(__nullable EXCachedResourceProgressBlock)progressBlock 48 successBlock:(EXCachedResourceSuccessBlock)successBlock 49 errorBlock:(EXCachedResourceErrorBlock)errorBlock; 50 51 @end 52 53 NS_ASSUME_NONNULL_END 54