Je tente de confirmer la mise en cache d'URL en enregistrant les statistiques de la mémoire autour d'un NSURLCache.NSURLCache: indique sa mise en cache, n'est pas, et aucun changement dans les statistiques de la mémoire
J'ai prolongé la base NSURLCache comme suit:
@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
J'ai également le code de bouton qui exécute la commande suivante:
- (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);
}
Lorsque je clique sur certains boutons de test sur mon point de vue pour déclencher des événements URLConnection Je vois ces méthodes étant appelées avec les bonnes adresses URL. Cependant, la mémoire cache et les statistiques d'utilisation du disque NE changent JAMAIS.
Exemple de journal
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
Cela me fait croire:
1 - Je fais quelque chose de mal, et ne pas observer correctement le comportement du cache
2 - Ce cache est pas vraiment mise en cache
Toutes les pensées seraient très appréciées.