title: Delete Cache with UIWebview in an iOS application
body: <p>I have a problem with UIWebview. I call several time an url for print a pictures in my webview and I count how many times my pictures was displayed.</p>
  
  <p>When I call the url of the pictures the count match to the number of printing.</p>
  
  <pre><code>NSURL *URL = [NSURL URLWithString:@"http://url_pictures.com"];
  NSURLRequest *request = [NSURLRequest requestWithURL:URL];
  [adView loadRequest:request];
  </code></pre>
  
  <p>When I call the url with loadhtmlstring my counter is to one. It's very important for me to use loadhtmlstring because my API returns me a html code with javascript.</p>
  
  <pre><code>NSString *html = @"&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;document.write(\"&lt;a target=\"_blank\"ref=\"http://url_redirect.com\"&gt;&lt;img border=\"0\" src=\"http://url_pictures.com\"&gt;&lt;/a&gt;\");&lt;/body&gt;&lt;/html&gt;";
  NSString *baseURL = [mbAdUtil getBaseURL:html];
  NSString *script = [[NSString alloc] initWithFormat:@"%@", html];
  [adView loadHTMLString:script baseURL:[NSURL URLWithString:baseURL]];
  </code></pre>
  
  <p>I tested a lot of things that my counter is egal to printing.</p>
  
  <p>this is some example of what I tested :</p>
  
  <pre><code>[webView loadHTMLString:@"" baseURL:nil];
  [webView stopLoading]; 
  [webView setDelegate:nil];
  [webView removeFromSuperview];
  </code></pre>
  
  <p>Another :</p>
  
  <pre><code>// remove all cached responses
  [[NSURLCache sharedURLCache] removeAllCachedResponses];
  
  // set an empty cache
  NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
  [NSURLCache setSharedURLCache:sharedCache];
  
  // remove the cache for a particular request
  [[NSURLCache sharedURLCache] removeCachedResponseForRequest:request];
  </code></pre>
  
  <p>Also, I tested by destroying my instance of my project and create another.
  I destroyed my webview, all my variable... and so much else that I can not remember.
  My counter is always 1.</p>
  
  <p>My better solution is :</p>
  
  <pre><code>[webView loadHTMLString:@"" baseURL:nil];
  [webView stopLoading]; 
  [webView setDelegate:nil];
  [webView removeFromSuperview];
  </code></pre>
  
  <p>With this I count 2 to 3 printing but the visual result is not that I expect.</p>