Created
March 11, 2011 15:14
-
-
Save gorenje/865994 to your computer and use it in GitHub Desktop.
cib data caching based on urls. This is simplest case, no loadDelegate is supported.
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
/* | |
* Store all CIB data on a url-data basis in this dictionary. To prevent cibs from | |
* being continously downloaded by the CPWindowController, or rather the CPCib, we | |
* override the responsible init method and cache the data. | |
*/ | |
CibDataCacheDictionary = [CPDictionary dictionary]; | |
@implementation CPCib (CacheDataResponse) | |
/* | |
* The argument, at least in the current application, always seems to be a CPString. | |
* So we can assume that, and append a timestamp to avoid caching problems. | |
*/ | |
- (id)initWithContentsOfURL:(CPURL)aURL | |
{ | |
self = [super init]; | |
if (self) | |
{ | |
if ( [CibDataCacheDictionary objectForKey:aURL] ) { | |
_data = [CPData dataWithRawString:[[CibDataCacheDictionary | |
objectForKey:aURL] rawString]]; | |
} else { | |
var request = [CPURLRequest | |
requestWithURL:[aURL stringByAppendingFormat:"?%s", | |
[CPString timestamp]]]; | |
_data = [CPURLConnection sendSynchronousRequest:request returningResponse:nil]; | |
[CibDataCacheDictionary setObject:_data forKey:aURL]; | |
} | |
_awakenCustomResources = YES; | |
} | |
return self; | |
} | |
@end | |
@implementation CPString (IsBlank) | |
+ (CPString)timestamp | |
{ | |
return [CPString stringWithFormat:"%d", new Date().getTime()]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment