CSURLCache
はオフライン ブラウジング用のリソースをキャッシュするように設計されており、NSURLCache
データはメモリ内にのみ保存されます。
cachedResponse
アプリケーションがクラッシュする前に自動解放された場合、そうでない場合、オブジェクトは単にリークされます。
これに当てられる可能性のある光は大歓迎です。
stringByEncodingURLEntities
上のカテゴリ方法ですのでご注意くださいNSString
。
@interface CSURLCache : NSURLCache {} @end
@implementation CSURLCache
- (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request
{
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:[[[request URL] absoluteString] stringByEncodingURLEntities]];
if ([[NSFileManager defaultManager] fileExistsAtPath:path])
{
NSData *data = [[NSData alloc] initWithContentsOfFile:path];
NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[request URL]
MIMEType:nil
expectedContentLength:[data length]
textEncodingName:nil];
NSCachedURLResponse *cachedResponse = [[NSCachedURLResponse alloc] initWithResponse:response
data:data];
[response release];
[data release];
return cachedResponse;
}
return nil;
}
@end
更新: Apple にレーダーを送信したところ、これは既知の問題であることがわかりました (レーダー #7640470)。