SDMDownloadCache class

Deprecated. Download cache to store http responses.Please note that the download cache does not work with ODPRequest via SUP. [[DownloadCache instance] setDefaultCachePolicy:OnlyLoadIfNotCachedCachePolicy];

Syntax

@interface SDMDownloadCache : NSObject <SDMCacheDelegate>

Members

All members of SDMDownloadCache, including inherited members.

Methods
Method Description
+ (id) instance Static DownloadCache instance Used as a global cache To make HTTPRequests use it automatically, use [HTTPRequest setDefaultCache:[DownloadCache sharedCache]];.
+ (NSDateFormatter *) rfc1123DateFormatter  
+ (BOOL) serverAllowsResponseCachingForRequest: (SDMHttpRequest *) request A helper function that determines if the server has requested data should not be cached by looking at the request's response headers.
Inherited members from SDMCacheDelegate
Member Description
- (NSDictionary *) cachedHeadersForRequest: (id< SDMRequesting >) request Should return an NSDictionary of cached headers for the passed request, if it is stored in the cache.
- (NSData *) cachedResponseDataForRequest: (id< SDMRequesting >) request Should return the cached body of a response for the passed request, if it is stored in the cache.
- (void) clearCachedResponsesForStoragePolicy: (CacheStoragePolicy) cachePolicy Clear cached data stored for the passed storage policy.
- (CachePolicy) defaultCachePolicy Should return the cache policy that will be used when requests have their cache policy set to DefaultCachePolicy.
- (BOOL) isCachedDataCurrentForRequest: (id< SDMRequesting >) request Should return YES if the cache considers its cached response current for the request Should return NO if the data is not cached, or (for example) if the cached headers state the request should have expired.
- (NSString *) pathToCachedResponseDataForRequest: (id< SDMRequesting >) request Same as the above, but returns a path to the cached response body instead.
- (void) removeCachedDataForRequest: (id< SDMRequesting >) request Should Remove cached data for a particular request.
- (void) storeResponseForRequest: (id< SDMRequesting >) request maxAge: (NSTimeInterval) maxAge Should store the response for the passed request in the cache When a non-zero maxAge is passed, it should be used as the expiry time for the cached response.

Example 1

// assign the download cache to our request
[m_AsynchRequest setDownloadCache:[SDMDownloadCache instance]];
// fine-tune cache settings
[m_AsynchRequest setCacheStoragePolicy:CachePermanentlyCacheStoragePolicy];
// ...

Slightly more advanced technique 
// check for network reachability
int reachabilityStatus = [[Reachability reachabilityForInternetConnection] currentReachabilityStatus];
// use cached content if no network
if (reachabilityStatus == NotReachable) {
    [[SDMDownloadCache instance] setDefaultCachePolicy:UseCacheIfLoadFailsCachePolicy];
}
else {
    [[SDMDownloadCache instance] setDefaultCachePolicy:OnlyLoadIfNotCachedCachePolicy];
}

Deprecated