Skip to content

Instantly share code, notes, and snippets.

@veader
Created August 31, 2010 14:06
Show Gist options
  • Save veader/559071 to your computer and use it in GitHub Desktop.
Save veader/559071 to your computer and use it in GitHub Desktop.
+ (void)clearCaches {
// clear any URL caches
[[NSURLCache sharedURLCache] removeAllCachedResponses];
// clear any cookie caches
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://%@/", kAPIHost]];
for (NSHTTPCookie *cookie in [cookieStorage cookiesForURL:url]) {
[cookieStorage deleteCookie:cookie];
}
// attempt to clear any credential caches
NSURLCredentialStorage *credentialStorage = [NSURLCredentialStorage sharedCredentialStorage];
NSDictionary *credentialsDicationary = [credentialStorage allCredentials];
for (NSURLProtectionSpace *space in [credentialsDicationary allKeys]) {
NSDictionary *spaceDictionary = [credentialsDicationary objectForKey:space];
for (id userName in [spaceDictionary allKeys]) {
NSURLCredential *credential = [spaceDictionary objectForKey:userName];
[credentialStorage removeCredential:credential forProtectionSpace:space];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment