-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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
- Loading branch information
Showing
5 changed files
with
120 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
AFCache should not know AFCacheManager to not only avoid cyclic dependencies but also to all AFCache being included without requiring to (implicitly) include AFCacheManager.