Note that there are some explanatory texts on larger screens.

plurals
  1. POASIHTTPRequest Download cache problem - unable to save/load date in cache
    primarykey
    data
    text
    <p>I am trying to save data into cache using ASIHTTP (<a href="http://allseeing-i.com/ASIHTTPRequest/How-to-use#using_a_download_cache" rel="nofollow noreferrer">http://allseeing-i.com/ASIHTTPRequest/How-to-use#using_a_download_cache</a>). I am not sure what I am doing wrong but it seems not to be storing data into cache. The output of the following code is this:</p> <pre><code>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 </code></pre> <p>Here is the code:</p> <pre><code>[[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")); </code></pre> <p>Can someone give me some code snippet on how to accomplish this?</p> <h2>Thanks!</h2> <h2>-----------------------------------------------------------------------</h2> <p><strong>NEW CODE REVISION:</strong></p> <pre><code>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(@"------------&gt;&gt;&gt;&gt;&gt;&gt;&gt; Success is %@\n", (success ? @"YES" : @"NO")); NSData *responseData = [request responseData]; UIImage *image = [[UIImage alloc] initWithData:responseData]; </code></pre> <p>This only works with [request startSynchronous]; if I try Asynchronous method, it dosent call this function:</p> <pre><code>- (void)requestFinished:(ASIHTTPRequest *)request </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload