Memory NSURLCache:表示它的缓存不是,并且内存状态没有变化
我试图通过记录NSURLCache周围的内存统计信息来确认URL缓存 我已将基本NSURLCache扩展如下:Memory NSURLCache:表示它的缓存不是,并且内存状态没有变化,memory,ios6,nsurlconnection,nsurlcache,disk-access,Memory,Ios6,Nsurlconnection,Nsurlcache,Disk Access,我试图通过记录NSURLCache周围的内存统计信息来确认URL缓存 我已将基本NSURLCache扩展如下: @implementation MarksCache : NSURLCache - (NSCachedURLResponse *) cachedResponseForRequest:(NSURLRequest *)request; { NSString *myString = [request.URL absoluteString]; DDLogVerbose(@"
@implementation MarksCache : NSURLCache
- (NSCachedURLResponse *) cachedResponseForRequest:(NSURLRequest *)request;
{
NSString *myString = [request.URL absoluteString];
DDLogVerbose(@"URL CACHE GET : PRE : %@ %d %d %d %d", myString,
[NSURLCache sharedURLCache].currentDiskUsage ,
[NSURLCache sharedURLCache].currentMemoryUsage,
[NSURLCache sharedURLCache].diskCapacity,
[NSURLCache sharedURLCache].memoryCapacity);
NSCachedURLResponse *resp = [super cachedResponseForRequest:request];
//NSURLResponse *rp = [resp response];
//NSString *rpdesc = [rp description];
//NSData *data = [resp data];
//NSString *respdesc = [resp description];
//NSString *selfdesc = [super description];
DDLogVerbose(@"URL CACHE GET : POST : %@ %d %d %d %d", myString,
[NSURLCache sharedURLCache].currentDiskUsage ,
[NSURLCache sharedURLCache].currentMemoryUsage,
[NSURLCache sharedURLCache].diskCapacity,
[NSURLCache sharedURLCache].memoryCapacity);
return resp;
}
- (void)storeCachedResponse:(NSCachedURLResponse *)cachedResponse forRequest:(NSURLRequest *)request
{
NSString *myString = [request.URL absoluteString];
DDLogVerbose(@"URL CACHE SET : PRE : %@ %d %d %d %d", myString,
[NSURLCache sharedURLCache].currentDiskUsage ,
[NSURLCache sharedURLCache].currentMemoryUsage,
[NSURLCache sharedURLCache].diskCapacity,
[NSURLCache sharedURLCache].memoryCapacity);
[super cachedResponseForRequest:request];
DDLogVerbose(@"URL CACHE SET : POST : %d %d %d %d",
[NSURLCache sharedURLCache].currentDiskUsage ,
[NSURLCache sharedURLCache].currentMemoryUsage,
[NSURLCache sharedURLCache].diskCapacity,
[NSURLCache sharedURLCache].memoryCapacity);
}
@end
我还有执行以下操作的按钮代码:
- (IBAction)onClearButtonPress:(id) sender{
DDLogVerbose(@"TestViewController onClearButtonPress : START : PRE : %d %d %d %d",
[NSURLCache sharedURLCache].currentDiskUsage ,
[NSURLCache sharedURLCache].currentMemoryUsage,
[NSURLCache sharedURLCache].diskCapacity,
[NSURLCache sharedURLCache].memoryCapacity);
[NSURLCache sharedURLCache].removeAllCachedResponses;
DDLogVerbose(@"TestViewController onClearButtonPress : START : POST : %d %d %d %d",
[NSURLCache sharedURLCache].currentDiskUsage ,
[NSURLCache sharedURLCache].currentMemoryUsage,
[NSURLCache sharedURLCache].diskCapacity,
[NSURLCache sharedURLCache].memoryCapacity);
}
当我单击视图上的一些测试按钮来触发URLConnection事件时,我看到这些方法被正确的URL调用。但是,缓存内存和磁盘使用情况统计数据永远不会改变
来自日志的示例
URL CACHE SET : PRE : https://<domain.com>/resources/images/bg/bg-blue.png 1970176 0 10000000 512000
URL CACHE SET : POST : https://<domain.com>/resources/images/bg/bg-blue.png 1970176 0 10000000 512000
URL CACHE GET : PRE : https://<domain.com>/resources/images/bg/bg-footer.png 1970176 0 10000000 512000
URL CACHE GET : POST : https://<domain.com>/resources/images/bg/bg-footer.png 1970176 0 10000000 512000
TestViewController onClearButtonPress : START : PRE : 1970176 0 10000000 512000
TestViewController onClearButtonPress : EXIT : POST : 1970176 0 10000000 512000
URL CACHE SET : PRE : https://<domain.com>/resources/images/bg/bg-footer.png 1970176 0 10000000 512000
URL CACHE SET : POST : https://<domain.com>/resources/images/bg/bg-footer.png 1970176 0 10000000 512000
URL缓存集:PRE:https:///resources/images/bg/bg-blue.png 1970176 0 10000000 512000
URL缓存集:发布:https:///resources/images/bg/bg-blue.png 1970176 0 10000000 512000
URL缓存获取:PRE:https:///resources/images/bg/bg-footer.png 1970176 0 10000000 512000
URL缓存获取:发布:https:///resources/images/bg/bg-footer.png 1970176 0 10000000 512000
TestViewController OnClearButton按:开始:前:1970176 0 10000000 512000
TestViewController OnClearButton按:退出:POST:1970176 0 10000000 512000
URL缓存集:PRE:https:///resources/images/bg/bg-footer.png 1970176 0 10000000 512000
URL缓存集:发布:https:///resources/images/bg/bg-footer.png 1970176 0 10000000 512000
这让我相信:
1-我做错了什么,没有正确地观察缓存行为
2-此缓存不是真正的缓存
任何想法都将不胜感激 我不久前就明白了这一点,想发布答案。 我已将我的代码作为代表:
NSURLConnection-连接:willCacheResponse
该方法允许您在缓存行为发生之前覆盖它。我只是简单地将日志放在其中,以查看我的响应是否可缓存,而忘记了实际执行任何缓存。一旦修复,我的内存统计日志确实显示了项目进入和退出缓存