mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-02 22:42:45 +08:00
* Introduces RKRequestCache for cacheing responses (supports ETag conditional GET, use cache if available, use cache on error, etc.) closes #75 * Updates to Three20 layer to eliminate need for intermediary TTTableItem classes closes #76 * Fixes to ensure iOS 3.x compatability: * Switched compiler to Clang * Updated conditional checks for UIBackgroundTask symbols to ensure runtime safety on iOS 3.x * Removed unnecessary linkage against UIKit and CoreFoundation from library targets * Fix for issue where RKRequest objects could become stuck in infinite loop within RKRequestQueue loadNextInQueue if you start a request and then cancel immediately. On cancel only decrement loadCount if the request has start loading. refs #122
58 lines
1.8 KiB
Objective-C
58 lines
1.8 KiB
Objective-C
//
|
|
// RKRequestCache.h
|
|
// RestKit
|
|
//
|
|
// Created by Jeff Arena on 4/4/11.
|
|
// Copyright 2011 Two Toasters. All rights reserved.
|
|
//
|
|
|
|
#import "RKRequest.h"
|
|
#import "RKResponse.h"
|
|
|
|
|
|
/**
|
|
* Storage policy. Determines if we clear the cache out when the app is shut down.
|
|
* Cache instance needs to register for
|
|
*/
|
|
typedef enum {
|
|
RKRequestCacheStoragePolicyDisabled, // The cache has been disabled. Attempts to store data will silently fail
|
|
RKRequestCacheStoragePolicyForDurationOfSession, // Cache data for the length of the session. Clear cache at app exit.
|
|
RKRequestCacheStoragePolicyPermanently // Cache data permanently, until explicitly expired or flushed
|
|
} RKRequestCacheStoragePolicy;
|
|
|
|
|
|
@interface RKRequestCache : NSObject {
|
|
NSString* _cachePath;
|
|
RKRequestCacheStoragePolicy _storagePolicy;
|
|
NSRecursiveLock* _cacheLock;
|
|
}
|
|
|
|
@property (nonatomic, readonly) NSString* cachePath; // Full path to the cache
|
|
@property (nonatomic, assign) RKRequestCacheStoragePolicy storagePolicy; // User can change storage policy.
|
|
|
|
+ (NSDateFormatter*)rfc1123DateFormatter;
|
|
|
|
- (id)initWithCachePath:(NSString*)cachePath storagePolicy:(RKRequestCacheStoragePolicy)storagePolicy;
|
|
|
|
- (NSString*)pathForRequest:(RKRequest*)request;
|
|
|
|
- (BOOL)hasResponseForRequest:(RKRequest*)request;
|
|
|
|
- (void)storeResponse:(RKResponse*)response forRequest:(RKRequest*)request;
|
|
|
|
//- (void)storeResponse:(RKResponse*)response forRequest:(RKRequest*)request expires:(NSTimeInterval)expirationAge;
|
|
|
|
- (RKResponse*)responseForRequest:(RKRequest*)request;
|
|
|
|
- (NSDictionary*)headersForRequest:(RKRequest*)request;
|
|
|
|
- (NSString*)etagForRequest:(RKRequest*)request;
|
|
|
|
- (void)invalidateRequest:(RKRequest*)request;
|
|
|
|
- (void)invalidateWithStoragePolicy:(RKRequestCacheStoragePolicy)storagePolicy;
|
|
|
|
- (void)invalidateAll;
|
|
|
|
@end
|