title: How to refresh a webview's cache?
body: <p>I am building a native app, where (at least) one part is a web app, disguised as a native app. Where Facebook showed us how important it is to use good caching, I'm caching the webpage, so it feels like a native part of the app when you load it for the second time. However, the way I've set it up, the cached content is permanent. So if I change something on the server, the old cached content still shows.</p>
  
  <p>Here's what I'd like the achieve in the order of preferability, 1 being the most preferable.</p>
  
  <ol>
  <li>EITHER The cached content shows first. In the background, the page checks for a newer version, but only reloads if the content is different.</li>
  <li>OR The cached content shows first. In the background the page refreshes and reloads.</li>
  <li>OR The cached content is erased after X time (a week?), forcing the page to reload.</li>
  </ol>
  
  <p>The last option is the least preferable, since everytime the page reloads, it feels slow and horrible. The second option is the way my native activities behave (show cache first, refresh in background. However, this jumps users to the top of a list if they've scrolled down in the meantime.). First would be absolutely perfect!</p>
  
  <p>Here's the code I'm currently using.</p>
  
  <pre><code>WebView wv = (WebView) v.findViewById(ref_id);
  wv.getSettings().setJavaScriptEnabled(true);
  wv.getSettings().setDatabaseEnabled(true);
  String appDBPath = v.getContext().getApplicationContext().getDatabasePath("AppConstructor").getAbsolutePath();
  
      wv.setWebChromeClient(new WebChromeClient() {
          @Override
          public void onReachedMaxAppCacheSize(long spaceNeeded,
                  long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
              quotaUpdater.updateQuota(spaceNeeded * 2);
          }
  
          @Override
          public void onExceededDatabaseQuota(String url,
                  String databaseIdentifier, long currentQuota,
                  long estimatedSize, long totalUsedQuota,
                  WebStorage.QuotaUpdater quotaUpdater) {
              quotaUpdater.updateQuota(estimatedSize * 2);
          }
      });
  
  wv.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
  wv.getSettings().setDomStorageEnabled(true);
  wv.getSettings().setAppCacheMaxSize(1024 * 1024 * 8);
  String appCachePath = v.getContext().getApplicationContext().getCacheDir().getAbsolutePath();
  wv.getSettings().setAppCachePath(appCachePath);
  wv.getSettings().setAllowFileAccess(true);
  wv.getSettings().setAppCacheEnabled(true);
  wv.loadUrl(ref_arg1);
  Core x = new Core();
  wv.addJavascriptInterface(x.new JavaScriptInterface(v.getContext()),"Android");
  </code></pre>
  
  <p>Any help would be greatly appreciated!</p>