ASIHTTPRequest Ошибка загрузки кеша - невозможно сохранить / загрузить дату в кеш

Я пытаюсь сохранить данные в кэш с помощью ASIHTTP ( http://allseeing-i.com/ASIHTTPRequest/How -в использование # using_a_download_cache ). Я не уверен, что я делаю неправильно, но кажется, что данные не хранятся в кеше. Вывод следующего кода:

2010-08-12 15:44:13.801 TabBar[51728:207] Success is YES
2010-08-12 15:44:13.802 TabBar[51728:207] Success is NO
2010-08-12 15:44:13.804 TabBar[51728:207] Success is YES
2010-08-12 15:44:13.805 TabBar[51728:207] S-----------
2010-08-12 15:44:13.874 TabBar[51728:207] Success is YES
2010-08-12 15:44:13.874 TabBar[51728:207] Success is NO
2010-08-12 15:44:13.876 TabBar[51728:207] Success is YES

Вот код:

[[ASIDownloadCache sharedCache] clearCachedResponsesForStoragePolicy:
                              ASICacheForSessionDurationCacheStoragePolicy];
[[ASIDownloadCache sharedCache] 
                    setDefaultCachePolicy:ASIOnlyLoadIfNotCachedCachePolicy];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL 
                                URLWithString:@"http://www.nytimes.com/"]];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request startSynchronous];

request = [ASIHTTPRequest requestWithURL:[NSURL 
                                URLWithString:@"http://www.nytimes.com/"]];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request startSynchronous];
BOOL success = ([request responseStatusCode] == 200);
NSLog(@"Success is %@\n", (success ? @"YES" : @"NO"));

success = [request didUseCachedResponse];
NSLog(@"Success is %@\n", (success ? @"YES" : @"NO"));

success = ([[request responseData] length]);
NSLog(@"Success is %@\n", (success ? @"YES" : @"NO"));

NSLog(@"S-----------");
request = [ASIHTTPRequest requestWithURL:[NSURL 
                    URLWithString:@"http://www.nytimes.com/"]];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request startSynchronous];
success = ([request responseStatusCode] == 200);
NSLog(@"Success is %@\n", (success ? @"YES" : @"NO"));

success = [request didUseCachedResponse];
NSLog(@"Success is %@\n", (success ? @"YES" : @"NO"));

success = ([[request responseData] length]);
NSLog(@"Success is %@\n", (success ? @"YES" : @"NO"));

Может кто-нибудь дать мне фрагмент кода о том, как это сделать?

Спасибо!

-------------------------- ---------------------------------------------

НОВЫЙ КОД ПЕРЕСМОТР:

NSURL *url = [NSURL URLWithString:imageURL];

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
[request setCachePolicy:ASIOnlyLoadIfNotCachedCachePolicy];
[request setSecondsToCache:60*60*24*30]; // Cache for 30 days

[request startSynchronous];//startAsynchronous];

BOOL success = [request didUseCachedResponse];
NSLog(@"------------>>>>>>> Success is %@\n", (success ? @"YES" : @"NO"));

NSData *responseData = [request responseData];
UIImage *image = [[UIImage alloc] initWithData:responseData];

Это работает только с [request startSynchronous]; если я пытаюсь использовать асинхронный метод, он не вызывает эту функцию:

- (void)requestFinished:(ASIHTTPRequest *)request

5
задан user348398 15 August 2010 в 19:54
поделиться