Skip to content

Instantly share code, notes, and snippets.

@seanhess
Created December 1, 2010 18:37
Show Gist options
  • Save seanhess/723973 to your computer and use it in GitHub Desktop.
Save seanhess/723973 to your computer and use it in GitHub Desktop.
- (void)testDiskCache {
// Test that we hit the disk cache
// First, nuke the cache, run it once, then clear the memory cache
// Then, run the request again and make sure it loads from cache
[[TVURLCache sharedCache] nuke];
NSString * value = @"testDiskCache";
NSString * url = @"http://testDiskCache";
[self callURL:url withReturnString:value callback: ^(TVURLRequest * request) {
TVURLCache * cache = [TVURLCache sharedCache];
GHAssertTrue([cache diskCacheExists], @"Disk Cache was not created");
[cache flush];
[[TVURLCache sharedCache] clearMemoryCache];
// This is required for async tests
[self prepare];
[cache setOnNextSave:^ {
// I think I needed to get back on the main thread
[[NSOperationQueue mainQueue] addOperationWithBlock:^ {
[self callURL:url withReturnString:@"NOT EQUAL TO ME" callback: ^(TVURLRequest * request) {
TVGetRequest * getRequest = (TVGetRequest*)request;
GHAssertTrue(getRequest.hitCache, @"Disk - Should have hit the cache from disk");
GHAssertEqualObjects(request.stringValue, value, [NSString stringWithFormat:@"Disk - Value should be equal to the original cached value %@", request.stringValue]);
[self notify:kGHUnitWaitStatusSuccess forSelector:@selector(testDiskCache)];
}];
}];
}];
// It doesn't delay for 10 seconds, that's just the timeout
[self waitForStatus:kGHUnitWaitStatusSuccess timeout:2.0];
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment