New version is available You are viewing the documentation for JxBrowser 6 which is not supported since December 2019. Go to the current documentation.
List icon 目录

This guide describes the cache types supported by Chromium and shows how to work with them.

Chromium supports the following cache types:

  • HTTP cache
  • Blink cache
  • HTML5 AppCache

When any resource request is made from a page, it first goes through the Blink loader and the Blink cache. A request to the browser process may or may not be issued from there. As it goes through the browser’s network stack, it reaches the HTTP (disk or memory) cache. There is no explicit communication from a page to the cache.

HTML5 AppCache is used explicitly by a web page. It stores data independently from the other caches.

Clearing Cache

Chromium API doesn’t provide functionality that allows disabling cache at all, but it provides functionality that allows clearing cache storage. The following example demonstrates how to clear persistent cache storage using JxBrowser Cache API:

import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.BrowserContext;

/**
 * This sample demonstrates how to clear the Browser's cache. If you create
 * several browser instances by calling new Browser() or
 * new Browser(BrowserContext context) method using the same
 * BrowserContext instance, calling CacheStorage.clearCache()
 * will remove cache for all these browser instances.
 */
public class ClearCacheSample {
    public static void main(String[] args) {
        BrowserContext context1 = new BrowserContext("C:\\my-data1");
        Browser browser1 = new Browser(context1);
        Browser browser2 = new Browser(context1);

        BrowserContext context2 = new BrowserContext("C:\\my-data2");
        Browser browser3 = new Browser(context2);

        // Clears cache of browser1 and browser2 instances because they use the same
        // user data and cache "C:\\my-data1" directory. It doesn't clear cache
        // of browser3, because browser3 uses a different directory for storing
        // cache data - "C:\\my-data2".
        browser1.getCacheStorage().clearCache();
    }
}
Go Top