Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange NSURLConnection caching behaviour
    primarykey
    data
    text
    <p>I have a simple method that takes a url and loads it from the server:</p> <pre><code>- (void)loadURL:(NSString*)url { NSMutableURLRequest* request = [[NSMutableURLRequest alloc] init]; request.HTTPMethod = @"GET"; request.URL = [NSURL URLWithString:url]; NSHTTPURLResponse* response; [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:nil]; } </code></pre> <p>The server returns a response with max-age of 1 day.</p> <p>Problem is that when I run these 3 lines repeatedly, 2 of them randomly miss the cache and reload the response:</p> <pre><code>[self loadURL:@"http://192.168.0.105:8080/users/51bdbc73808897302f000001/avatar?size=200x200&amp;access_token=abcdefghijklmnopqrstuvwxyzzp77eDLqub3EWfXGe4c09RoyipmXgcENwfE6EV9yzvgp5VTSZww"]; [self loadURL:@"http://192.168.0.105:8080/users/51ee9d4e263d08fe04000003/avatar?size=200x200&amp;access_token=abcdefghijklmnopqrstuvwxyzzp77eDLqub3EWfXGe4c09RoyipmXgcENwfE6EV9yzvgp5VTSZww"]; [self loadURL:@"http://192.168.0.105:8080/users/51d17b81de38c60b20000006/avatar?size=200x200&amp;access_token=abcdefghijklmnopqrstuvwxyzzp77eDLqub3EWfXGe4c09RoyipmXgcENwfE6EV9yzvgp5VTSZww"]; </code></pre> <p>If I add some random unique data (&amp;x, &amp;y, &amp;z) to each request's query string it fixes the problem:</p> <pre><code>[self loadURL:@"http://192.168.0.105:8080/users/51bdbc73808897302f000001/avatar?size=200x200&amp;access_token=abcdefghijklmnopqrstuvwxyzzp77eDLqub3EWfXGe4c09RoyipmXgcENwfE6EV9yzvgp5VTSZww&amp;x"]; [self loadURL:@"http://192.168.0.105:8080/users/51ee9d4e263d08fe04000003/avatar?size=200x200&amp;access_token=abcdefghijklmnopqrstuvwxyzzp77eDLqub3EWfXGe4c09RoyipmXgcENwfE6EV9yzvgp5VTSZww&amp;y"]; [self loadURL:@"http://192.168.0.105:8080/users/51d17b81de38c60b20000006/avatar?size=200x200&amp;access_token=abcdefghijklmnopqrstuvwxyzzp77eDLqub3EWfXGe4c09RoyipmXgcENwfE6EV9yzvgp5VTSZww&amp;z"]; </code></pre> <p>Also, if I reduce the length of query strings to 80 chars it fixes the problem as well:</p> <pre><code>[self loadURL:@"http://192.168.0.105:8080/users/51bdbc73808897302f000001/avatar?size=200x200&amp;access_token=abcdefghijklmnopqrstuvwxyzzp77eDLqub3EWfXGe4c09Royipm"]; [self loadURL:@"http://192.168.0.105:8080/users/51ee9d4e263d08fe04000003/avatar?size=200x200&amp;access_token=abcdefghijklmnopqrstuvwxyzzp77eDLqub3EWfXGe4c09Royipm"]; [self loadURL:@"http://192.168.0.105:8080/users/51d17b81de38c60b20000006/avatar?size=200x200&amp;access_token=abcdefghijklmnopqrstuvwxyzzp77eDLqub3EWfXGe4c09Royipm"]; </code></pre> <p>What's going on? Is this a bug in iOS? How can I fix it?</p> <p>P.S: I've tested this in an empty application with no extra stuff both on iOS 5 and 6.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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