From 0bc0f2f82c2d4eb82197445511c5734811b2ceba Mon Sep 17 00:00:00 2001 From: Sebastian Grimme Date: Tue, 29 Jul 2014 13:59:06 +0200 Subject: [PATCH 1/4] - first added AFCacheManager to manage mutiple named instances - removed deprecated context-code from AFCache - renamed context to name , because its a named cache, context has a different meaning --- AFCache.xcodeproj/project.pbxproj | 12 +++++ src/shared/AFCache.h | 2 - src/shared/AFCache.m | 67 +++++----------------------- src/shared/AFCacheManager.h | 25 +++++++++++ src/shared/AFCacheManager.m | 73 +++++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+), 59 deletions(-) create mode 100644 src/shared/AFCacheManager.h create mode 100644 src/shared/AFCacheManager.m diff --git a/AFCache.xcodeproj/project.pbxproj b/AFCache.xcodeproj/project.pbxproj index abe5551..85ad24a 100644 --- a/AFCache.xcodeproj/project.pbxproj +++ b/AFCache.xcodeproj/project.pbxproj @@ -88,6 +88,9 @@ C7503D47198640AA0032E451 /* AFDownloadOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = C7503D44198640AA0032E451 /* AFDownloadOperation.h */; }; C7503D48198640AA0032E451 /* AFDownloadOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = C7503D45198640AA0032E451 /* AFDownloadOperation.m */; }; C7503D49198640AA0032E451 /* AFDownloadOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = C7503D45198640AA0032E451 /* AFDownloadOperation.m */; }; + C799310A1987B974001A7724 /* AFCacheManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C79931081987B974001A7724 /* AFCacheManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; + C799310B1987B974001A7724 /* AFCacheManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C79931091987B974001A7724 /* AFCacheManager.m */; }; + C799310C1987C0BF001A7724 /* AFCacheManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C79931081987B974001A7724 /* AFCacheManager.h */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -214,6 +217,8 @@ C73C71CB19816F13008EDA23 /* AFRequestConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFRequestConfiguration.m; path = src/shared/AFRequestConfiguration.m; sourceTree = ""; }; C7503D44198640AA0032E451 /* AFDownloadOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFDownloadOperation.h; path = src/shared/AFDownloadOperation.h; sourceTree = ""; }; C7503D45198640AA0032E451 /* AFDownloadOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFDownloadOperation.m; path = src/shared/AFDownloadOperation.m; sourceTree = ""; }; + C79931081987B974001A7724 /* AFCacheManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFCacheManager.h; path = src/shared/AFCacheManager.h; sourceTree = ""; }; + C79931091987B974001A7724 /* AFCacheManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFCacheManager.m; path = src/shared/AFCacheManager.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -380,6 +385,8 @@ C73C71CB19816F13008EDA23 /* AFRequestConfiguration.m */, C7503D44198640AA0032E451 /* AFDownloadOperation.h */, C7503D45198640AA0032E451 /* AFDownloadOperation.m */, + C79931081987B974001A7724 /* AFCacheManager.h */, + C79931091987B974001A7724 /* AFCacheManager.m */, ); name = core; sourceTree = ""; @@ -536,6 +543,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + C799310A1987B974001A7724 /* AFCacheManager.h in Headers */, 05C9BB6F132A30E60087CEA1 /* AFCacheLib.h in Headers */, 046BEFAB152D180A00FE16B8 /* AFCache.h in Headers */, 046BEFAC152D180A00FE16B8 /* AFCacheableItem.h in Headers */, @@ -559,6 +567,7 @@ 05FA23841357543A00050BCB /* AFCache_Logging.h in Headers */, 05FA23891357544400050BCB /* AFCacheableItem.h in Headers */, 05FA238B1357544B00050BCB /* AFCacheableItemInfo.h in Headers */, + C799310C1987C0BF001A7724 /* AFCacheManager.h in Headers */, 05FA238C1357544C00050BCB /* AFPackageInfo.h in Headers */, 05FA238E1357544F00050BCB /* Constants.h in Headers */, 05FA238F1357545000050BCB /* DateParser.h in Headers */, @@ -796,6 +805,7 @@ buildActionMask = 2147483647; files = ( 05C9BAF3132A291B0087CEA1 /* AFCache.m in Sources */, + C799310B1987B974001A7724 /* AFCacheManager.m in Sources */, 05C9BAF5132A291B0087CEA1 /* AFCache+Mimetypes.m in Sources */, 05C9BAFA132A291B0087CEA1 /* AFCacheableItem.m in Sources */, 05C9BAFC132A291B0087CEA1 /* AFCacheableItem+Packaging.m in Sources */, @@ -901,6 +911,7 @@ isa = XCBuildConfiguration; buildSettings = { ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; + CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; @@ -925,6 +936,7 @@ isa = XCBuildConfiguration; buildSettings = { ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; + CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; diff --git a/src/shared/AFCache.h b/src/shared/AFCache.h index 3ce7428..97f45d4 100755 --- a/src/shared/AFCache.h +++ b/src/shared/AFCache.h @@ -184,8 +184,6 @@ typedef struct NetworkTimeoutIntervals { */ @property (nonatomic, assign) BOOL disableSSLCertificateValidation; -+ (AFCache*)cacheForContext:(NSString*)context; - - (NSString *)filenameForURL: (NSURL *) url; - (NSString *)filenameForURLString: (NSString *) URLString; - (NSString *)filePath: (NSString *) filename; diff --git a/src/shared/AFCache.m b/src/shared/AFCache.m index 1801265..a15251d 100755 --- a/src/shared/AFCache.m +++ b/src/shared/AFCache.m @@ -29,6 +29,7 @@ #include #import "AFRegexString.h" #import "AFCache_Logging.h" +#import "AFCacheManager.h" #if USE_ASSERTS #define ASSERT_NO_CONNECTION_WHEN_OFFLINE_FOR_URL(url) NSAssert( [(url) isFileURL] || [self isOffline] == NO, @"No connection should be opened if we're in offline mode - this seems like a bug") @@ -47,7 +48,6 @@ @interface AFCache() -@property (nonatomic, copy) NSString *context; @property (nonatomic, strong) NSMutableArray *downloadQueue; @property (nonatomic, strong) NSTimer *archiveTimer; @property (nonatomic, assign) BOOL wantsToArchive; @@ -56,34 +56,21 @@ @interface AFCache() - (void)serializeState:(NSDictionary*)infoStore; - (void)cancelAllClientItems; -- (id)initWithContext:(NSString*)context; @end @implementation AFCache -static AFCache *sharedAFCacheInstance = nil; -static NSMutableDictionary* AFCache_contextCache = nil; - #pragma mark singleton methods + (AFCache *)sharedInstance { - @synchronized(self) { - if (sharedAFCacheInstance == nil) { - sharedAFCacheInstance = [[self alloc] initWithContext:nil]; - sharedAFCacheInstance.diskCacheDisplacementTresholdSize = kDefaultDiskCacheDisplacementTresholdSize; - } - } - return sharedAFCacheInstance; + // left for backward compability + return [AFCacheManager defaultCache]; } #pragma mark init methods -- (id)initWithContext:(NSString*)context { - if (!context && sharedAFCacheInstance != nil) - { - return [AFCache sharedInstance]; - } - +- (id)init +{ self = [super init]; if (self) { @@ -99,17 +86,11 @@ - (id)initWithContext:(NSString*)context { name:UIApplicationWillTerminateNotification object:nil]; #endif - if (!AFCache_contextCache) { - AFCache_contextCache = [[NSMutableDictionary alloc] init]; - } - - if (context) { - [AFCache_contextCache setObject:[NSValue valueWithPointer:(__bridge const void *)(self)] forKey:context]; - } - - _context = [context copy]; + [self reinitialize]; [self initMimeTypes]; + + self.diskCacheDisplacementTresholdSize = kDefaultDiskCacheDisplacementTresholdSize; } return self; } @@ -166,12 +147,6 @@ - (void)initialize { - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; - - if (_context) - { - [AFCache_contextCache removeObjectForKey:_context]; - } - } - (NSUInteger)requestsPending { @@ -179,7 +154,7 @@ - (NSUInteger)requestsPending { } - (void)setDataPath:(NSString*)newDataPath { - if (self.context && self.dataPath) + if (self.dataPath) { NSLog(@"Error: Can't change data path on instanced AFCache"); NSAssert(NO, @"Can't change data path on instanced AFCache"); @@ -194,28 +169,6 @@ - (void)setDataPath:(NSString*)newDataPath { self.maxItemFileSize = fileSize; } -// TODO: If we really need "named" caches ("context" is the wrong word), then realize this concept as a category, but not here -+ (AFCache*)cacheForContext:(NSString *)context -{ - if (!AFCache_contextCache) - { - AFCache_contextCache = [[NSMutableDictionary alloc] init]; - } - - if (!context) - { - return [self sharedInstance]; - } - - AFCache* cache = [[AFCache_contextCache objectForKey:context] pointerValue]; - if (!cache) - { - cache = [[[self class] alloc] initWithContext:context]; - } - - return cache; -} - // The method reinitialize really initializes the cache. // This is usefull for testing, when you want to, uh, reinitialize @@ -249,7 +202,7 @@ -(void)addRedirectFromURL:(NSURL*)originalURL toURL:(NSURL*)redirectURL [self.urlRedirects setObject:[redirectURL absoluteString] forKey:[originalURL absoluteString]]; } --(void)addRedirectFromURLString:(NSString*)originalURLString toURLString:(NSString*)redirectURLString +-(void)addRedirectFromURLString:(NSString*)originalURLString toURL:(NSString*)redirectURLString { [self.urlRedirects setObject:redirectURLString forKey:originalURLString]; } diff --git a/src/shared/AFCacheManager.h b/src/shared/AFCacheManager.h new file mode 100644 index 0000000..45c2fbd --- /dev/null +++ b/src/shared/AFCacheManager.h @@ -0,0 +1,25 @@ +// +// AFCacheManager.h +// AFCache +// +// Created by Sebastian Grimme on 29.07.14. +// Copyright (c) 2014 Artifacts - Fine Software Development. All rights reserved. +// + +#import "AFCache.h" + +extern NSString *kAFCacheDefaultName; + +@interface AFCacheManager : NSObject + +/** + * @return default cache instance + */ ++ (AFCache*)defaultCache; + +/** + * @return named cache instance + */ ++ (AFCache*)cacheForName:(NSString*)name; + +@end diff --git a/src/shared/AFCacheManager.m b/src/shared/AFCacheManager.m new file mode 100644 index 0000000..8d374fd --- /dev/null +++ b/src/shared/AFCacheManager.m @@ -0,0 +1,73 @@ +// +// AFCacheManager.m +// AFCache +// +// Created by Sebastian Grimme on 29.07.14. +// Copyright (c) 2014 Artifacts - Fine Software Development. All rights reserved. +// + +#import "AFCacheManager.h" + +NSString *kAFCacheDefaultName = @"AFCacheDefaultName"; + +static AFCacheManager *sharedAFCacheManagerInstance = nil; + +@interface AFCacheManager () +@property (nonatomic, strong) NSMutableDictionary* instanceDictionary; +@end + +@implementation AFCacheManager + +#pragma mark singleton methods + ++ (AFCacheManager*)sharedManager { + @synchronized(self) { + if (sharedAFCacheManagerInstance == nil) { + sharedAFCacheManagerInstance = [[self alloc] init]; + } + } + return sharedAFCacheManagerInstance; +} + +#pragma mark - Lifecycle + +- (instancetype)init +{ + self = [super init]; + if (self) { + // create dictionary which holds all cache-instances + _instanceDictionary = [[NSMutableDictionary alloc] init]; + } + return self; +} + +#pragma mark - Private API + +- (AFCache*)cacheInstanceForName:(NSString *)name +{ + @synchronized (self.instanceDictionary) { + AFCache *cacheInstance = [[AFCacheManager sharedManager].instanceDictionary objectForKey:name]; + + if (!cacheInstance) { + cacheInstance = [[AFCache alloc] init]; + + [[AFCacheManager sharedManager].instanceDictionary setObject:cacheInstance forKey:name]; + } + + return cacheInstance; + } +} + +#pragma mark - static factory/get methods + ++ (AFCache*)defaultCache +{ + return [[AFCacheManager sharedManager] cacheInstanceForName:kAFCacheDefaultName]; +} + ++ (AFCache*)cacheForName:(NSString*)name +{ + return [[AFCacheManager sharedManager] cacheInstanceForName:name]; +} + +@end From 78ca83fa583cf46f27e4394e4e490f29fc253110 Mon Sep 17 00:00:00 2001 From: Sebastian Grimme Date: Tue, 29 Jul 2014 13:59:59 +0200 Subject: [PATCH 2/4] removed unused reference to Constants.h --- AFCache.xcodeproj/project.pbxproj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/AFCache.xcodeproj/project.pbxproj b/AFCache.xcodeproj/project.pbxproj index 85ad24a..d158851 100644 --- a/AFCache.xcodeproj/project.pbxproj +++ b/AFCache.xcodeproj/project.pbxproj @@ -77,7 +77,6 @@ 05FA238B1357544B00050BCB /* AFCacheableItemInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 05C9BAE8132A291B0087CEA1 /* AFCacheableItemInfo.h */; }; 05FA238C1357544C00050BCB /* AFPackageInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 05C9BAEA132A291B0087CEA1 /* AFPackageInfo.h */; }; 05FA238D1357544D00050BCB /* AFURLCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 05C9BAEC132A291B0087CEA1 /* AFURLCache.h */; }; - 05FA238E1357544F00050BCB /* Constants.h in Headers */ = {isa = PBXBuildFile; fileRef = 05C9BAEE132A291B0087CEA1 /* Constants.h */; }; 05FA238F1357545000050BCB /* DateParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 05C9BAEF132A291B0087CEA1 /* DateParser.h */; }; 05FA23901357548D00050BCB /* libAFCacheOSXStatic.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 05FA235F1357539B00050BCB /* libAFCacheOSXStatic.a */; }; C73C71CC19816F13008EDA23 /* AFRequestConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = C73C71CA19816F13008EDA23 /* AFRequestConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -177,7 +176,6 @@ 05C9BAEB132A291B0087CEA1 /* AFPackageInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFPackageInfo.m; path = src/shared/AFPackageInfo.m; sourceTree = ""; }; 05C9BAEC132A291B0087CEA1 /* AFURLCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFURLCache.h; path = src/shared/AFURLCache.h; sourceTree = ""; }; 05C9BAED132A291B0087CEA1 /* AFURLCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFURLCache.m; path = src/shared/AFURLCache.m; sourceTree = ""; }; - 05C9BAEE132A291B0087CEA1 /* Constants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Constants.h; path = src/shared/Constants.h; sourceTree = ""; }; 05C9BAEF132A291B0087CEA1 /* DateParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DateParser.h; path = src/shared/DateParser.h; sourceTree = ""; }; 05C9BAF0132A291B0087CEA1 /* DateParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DateParser.m; path = src/shared/DateParser.m; sourceTree = ""; }; 05C9BB08132A29370087CEA1 /* AFRegexString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFRegexString.h; sourceTree = ""; }; @@ -373,7 +371,6 @@ 05238D14151B6E470015D70E /* core */ = { isa = PBXGroup; children = ( - 05C9BAEE132A291B0087CEA1 /* Constants.h */, 05C9BADD132A291B0087CEA1 /* AFCache.h */, 05C9BADE132A291B0087CEA1 /* AFCache.m */, 05C9BAE3132A291B0087CEA1 /* AFCache+PrivateAPI.h */, @@ -569,7 +566,6 @@ 05FA238B1357544B00050BCB /* AFCacheableItemInfo.h in Headers */, C799310C1987C0BF001A7724 /* AFCacheManager.h in Headers */, 05FA238C1357544C00050BCB /* AFPackageInfo.h in Headers */, - 05FA238E1357544F00050BCB /* Constants.h in Headers */, 05FA238F1357545000050BCB /* DateParser.h in Headers */, 05FA238D1357544D00050BCB /* AFURLCache.h in Headers */, C7503D47198640AA0032E451 /* AFDownloadOperation.h in Headers */, From 55f24d0c35eaa6eb05090ff250e772abc8328075 Mon Sep 17 00:00:00 2001 From: Sebastian Grimme Date: Tue, 29 Jul 2014 14:55:56 +0200 Subject: [PATCH 3/4] improved comment only --- src/shared/AFCacheManager.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/AFCacheManager.m b/src/shared/AFCacheManager.m index 8d374fd..babcec2 100644 --- a/src/shared/AFCacheManager.m +++ b/src/shared/AFCacheManager.m @@ -35,7 +35,7 @@ - (instancetype)init { self = [super init]; if (self) { - // create dictionary which holds all cache-instances + // create dictionary which holds all named cache-instances _instanceDictionary = [[NSMutableDictionary alloc] init]; } return self; @@ -53,7 +53,7 @@ - (AFCache*)cacheInstanceForName:(NSString *)name [[AFCacheManager sharedManager].instanceDictionary setObject:cacheInstance forKey:name]; } - + return cacheInstance; } } From a73116b2eaa3b6060bf4d3923f2e9b243e418073 Mon Sep 17 00:00:00 2001 From: Sebastian Grimme Date: Tue, 29 Jul 2014 15:59:16 +0200 Subject: [PATCH 4/4] marked method sharedInstance as deprecated and prepared AFCache for next step (consider context in all situations) --- src/shared/AFCache.h | 3 ++- src/shared/AFCache.m | 4 ++++ src/shared/AFCacheManager.h | 2 +- src/shared/AFCacheManager.m | 8 ++++---- src/shared/AFCacheableItem.m | 2 ++ src/shared/AFHTTPURLProtocol.m | 6 ++++-- src/shared/AFURLCache.m | 8 ++++++-- 7 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/shared/AFCache.h b/src/shared/AFCache.h index 97f45d4..0da594e 100755 --- a/src/shared/AFCache.h +++ b/src/shared/AFCache.h @@ -191,7 +191,8 @@ typedef struct NetworkTimeoutIntervals { - (NSString *)fullPathForCacheableItem:(AFCacheableItem*)item; -+ (AFCache *)sharedInstance; ++ (AFCache *)sharedInstance __attribute__((deprecated("use defaultCache instead"))); ++ (AFCache *)defaultCache; - (AFCacheableItem *)cachedObjectForURL: (NSURL *) url diff --git a/src/shared/AFCache.m b/src/shared/AFCache.m index a15251d..88cbc2a 100755 --- a/src/shared/AFCache.m +++ b/src/shared/AFCache.m @@ -67,6 +67,10 @@ + (AFCache *)sharedInstance { return [AFCacheManager defaultCache]; } ++ (AFCache *)defaultCache { + return [AFCacheManager defaultCache]; +} + #pragma mark init methods - (id)init diff --git a/src/shared/AFCacheManager.h b/src/shared/AFCacheManager.h index 45c2fbd..7404a06 100644 --- a/src/shared/AFCacheManager.h +++ b/src/shared/AFCacheManager.h @@ -20,6 +20,6 @@ extern NSString *kAFCacheDefaultName; /** * @return named cache instance */ -+ (AFCache*)cacheForName:(NSString*)name; ++ (AFCache*)cacheNamed:(NSString*)name; @end diff --git a/src/shared/AFCacheManager.m b/src/shared/AFCacheManager.m index babcec2..26118d1 100644 --- a/src/shared/AFCacheManager.m +++ b/src/shared/AFCacheManager.m @@ -43,7 +43,7 @@ - (instancetype)init #pragma mark - Private API -- (AFCache*)cacheInstanceForName:(NSString *)name +- (AFCache*)cacheInstanceNamed:(NSString *)name { @synchronized (self.instanceDictionary) { AFCache *cacheInstance = [[AFCacheManager sharedManager].instanceDictionary objectForKey:name]; @@ -62,12 +62,12 @@ - (AFCache*)cacheInstanceForName:(NSString *)name + (AFCache*)defaultCache { - return [[AFCacheManager sharedManager] cacheInstanceForName:kAFCacheDefaultName]; + return [[AFCacheManager sharedManager] cacheInstanceNamed:kAFCacheDefaultName]; } -+ (AFCache*)cacheForName:(NSString*)name ++ (AFCache*)cacheNamed:(NSString*)name { - return [[AFCacheManager sharedManager] cacheInstanceForName:name]; + return [[AFCacheManager sharedManager] cacheInstanceNamed:name]; } @end diff --git a/src/shared/AFCacheableItem.m b/src/shared/AFCacheableItem.m index d465e70..03b9cee 100644 --- a/src/shared/AFCacheableItem.m +++ b/src/shared/AFCacheableItem.m @@ -65,6 +65,8 @@ - (AFCacheableItem*)initWithURL:(NSURL*)URL _url = URL; _cacheStatus = kCacheStatusFresh; _validUntil = _info.expireDate; + + // TODO: We cannot assume that this item's cache is the default sharedInstance _cache = [AFCache sharedInstance]; } return self; diff --git a/src/shared/AFHTTPURLProtocol.m b/src/shared/AFHTTPURLProtocol.m index d975f4f..1bd67a8 100644 --- a/src/shared/AFHTTPURLProtocol.m +++ b/src/shared/AFHTTPURLProtocol.m @@ -71,7 +71,8 @@ - (id)initWithRequest:(NSURLRequest *)aRequest - (void)startLoading { - [[AFCache sharedInstance] cachedObjectForRequest:self.request delegate:self]; + // this URL-Protocol works with defaultCache only + [[AFCache defaultCache] cachedObjectForRequest:self.request delegate:self]; } - (void) connectionDidFail: (AFCacheableItem *) cacheableItem { @@ -98,7 +99,8 @@ - (void)connectionHasBeenRedirected: (AFCacheableItem*) cacheableItem { - (void)stopLoading { - [[AFCache sharedInstance] cancelAsynchronousOperationsForURL:[[self request] URL] itemDelegate:self]; + // this URL-Protocol works with defaultCache only + [[AFCache defaultCache] cancelAsynchronousOperationsForURL:[[self request] URL] itemDelegate:self]; } - (NSCachedURLResponse *)cachedResponse { diff --git a/src/shared/AFURLCache.m b/src/shared/AFURLCache.m index 75c3805..fc0323f 100755 --- a/src/shared/AFURLCache.m +++ b/src/shared/AFURLCache.m @@ -29,7 +29,9 @@ @implementation AFURLCache -(NSCachedURLResponse*)cachedResponseForRequest:(NSURLRequest*)request { NSURL* url = request.URL; - AFCacheableItem* item = [[AFCache sharedInstance] cacheableItemFromCacheStore:url]; + + // this URL-Cache works with defaultCache only + AFCacheableItem* item = [[AFCache defaultCache] cacheableItemFromCacheStore:url]; if (item && item.cacheStatus == kCacheStatusFresh) { AFMediaTypeParser *parser = [[AFMediaTypeParser alloc] initWithMIMEType:item.info.mimeType]; @@ -64,7 +66,9 @@ - (void)storeCachedResponse:(NSCachedURLResponse *)cachedResponse forRequest:(NS expireDate = (expiresHeader) ? [DateParser gh_parseHTTP: expiresHeader] : nil; AFCacheableItem *item = [[AFCacheableItem alloc] initWithURL:request.URL lastModified:lastModified expireDate:expireDate contentType:contentTypeHeader]; - [[AFCache sharedInstance] importCacheableItem:item withData:cachedResponse.data]; + + // this URL-Cache works with defaultCache only + [[AFCache defaultCache] importCacheableItem:item withData:cachedResponse.data]; } }