Created
August 18, 2009 00:26
-
-
Save jfricker/169459 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // | |
| // JFDataCache.m | |
| // | |
| #import "JFDataCache.h" | |
| @implementation JFDataCache | |
| -(id)init { | |
| if (self = [super init]) { | |
| cache = [[NSMutableDictionary alloc] init]; | |
| } | |
| return self; | |
| } | |
| -(void)dealloc { | |
| [super dealloc]; | |
| [cache release]; | |
| } | |
| +(JFDataCache *)dataCacheInstance { | |
| static JFDataCache *instance; | |
| @synchronized(self) { | |
| if (!instance) { | |
| instance = [[JFDataCache alloc] init]; | |
| } | |
| } | |
| return instance; | |
| } | |
| -(id)getCachedItem:(NSString *)key { | |
| NSObject *object = nil; | |
| object = [cache objectForKey:key]; | |
| return object; | |
| } | |
| -(NSData *)getCachedData:(NSString *)key { | |
| NSData *object = nil; | |
| //NSLog(@"getting data for key %@", key); | |
| object = [cache objectForKey:key]; | |
| return object; | |
| } | |
| -(BOOL)dataInCache:(NSString *)key { | |
| return (nil != [cache objectForKey:key]); | |
| } | |
| -(void)saveItemToCache:(NSObject *)item forKey:(NSString *)key { | |
| //NSLog(@"caching item for key %@ : count %d", key, [cache count]); | |
| [cache setObject:item forKey:key]; | |
| } | |
| -(void)saveDataToCache:(NSData *)item forKey:(NSString *)key { | |
| //NSLog(@"caching data for key %@ : count %d", key, [cache count]); | |
| [cache setObject:item forKey:key]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment