Skip to content

Instantly share code, notes, and snippets.

View asakin's full-sized avatar

Ariel Sakin asakin

  • Boston
  • 00:56 (UTC -04:00)
View GitHub Profile
NSURL * serverUrl = [ NSURL URLWithString : @ "http://ATTACKER/SJ_headlines.json" ] ;
- ( void ) fetchArticles
{
NSURL * serverUrl = [ NSURL URLWithString : @ "http://skycure-journal.herokuapp.com" ] ;
NSMutableURLRequest * request = [ NSMutableURLRequest requestWithURL : serverUrl ] ;
[ request setValue : @ "application/json" forHTTPHeaderField : @ "Content-Type" ] ;
self.connection = [ [ NSURLConnection alloc ] initWithRequest : request delegate : self ] ;
}
@interface HRHResistantURLCache : NSURLCache
@end
@implementation HRHResistantURLCache
- (void)storeCachedResponse:(NSCachedURLResponse *)cachedResponse
forRequest:(NSURLRequest *)request
{
if (301 == [(NSHTTPURLResponse *)cachedResponse.response statusCode]) {
return;
#define DEFAULT_MEMORY_CAPACITY 512000
#define DEFAULT_DISK_CAPACITY 10000000
HRHResistantURLCache *myCache = [HRHResistantURLCache alloc];
[myCache initWithMemoryCapacity:DEFAULT_MEMORY_CAPACITY
diskCapacity:DEFAULT_DISK_CAPACITY
diskPath:@"MyCache.db"];
[NSURLCache setSharedURLCache:myCache];