FWRequest


@interface FWRequest : FWBaseRequest

FWRequest is the base class you should inherit to create your own request class. Based on FWBaseRequest, FWRequest adds local caching feature. Note download request will not be cached whatsoever, because download request may involve complicated cache control policy controlled by Cache-Control, Last-Modified, etc. https://github.com/yuantiku/YTKNetwork

  • Whether to use cache as response or not. Default is NO. If YES, which means caching will take effect with specific arguments. Note that cacheTimeInSeconds default is -1. As a result cache data is not actually used as response unless you return a positive value in cacheTimeInSeconds.

    Also note that this option does not affect storing the response, which means response will always be saved even useCacheResponse is NO.

    Declaration

    Objective-C

    @property (nonatomic) BOOL useCacheResponse;
  • Whether data is from local cache.

    Declaration

    Objective-C

    - (BOOL)isDataFromCache;
  • Manually load cache from storage.

    Declaration

    Objective-C

    - (BOOL)loadCacheWithError:(NSError *__autoreleasing _Nullable *_Nullable)error;

    Parameters

    error

    If an error occurred causing cache loading failed, an error object will be passed, otherwise NULL.

    Return Value

    Whether cache is successfully loaded.

  • Start request without reading local cache even if it exists. Use this to update local cache.

    Declaration

    Objective-C

    - (void)startWithoutCache;
  • Save response data (probably from another request) to this request’s cache location

    Declaration

    Objective-C

    - (void)saveResponseDataToCacheFile:(nonnull NSData *)data;

Subclass Override

  • The max time duration that cache can stay in disk until it’s considered expired. Default is -1, which means response is not actually saved as cache.

    Declaration

    Objective-C

    - (NSInteger)cacheTimeInSeconds;
  • Version can be used to identify and invalidate local cache. Default is 0.

    Declaration

    Objective-C

    - (long long)cacheVersion;
  • This can be used as additional identifier that tells the cache needs updating.

    Note

    The description string of this object will be used as an identifier to verify whether cache is invalid. Using NSArray or NSDictionary as return value type is recommended. However, If you intend to use your custom class type, make sure that description is correctly implemented.

    Declaration

    Objective-C

    - (nullable id)cacheSensitiveData;
  • Whether cache is asynchronously written to storage. Default is YES.

    Declaration

    Objective-C

    - (BOOL)writeCacheAsynchronously;

Getter

  • Undocumented

    Declaration

    Objective-C

    - (NSString *)cacheBasePath;