ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
默认情况下,Chromium引擎中启用了缓存。持久性缓存数据存储在Chromium数据目录的Cache文件夹中。例如,c:\ Users \ <用户名> \ AppData \ Local \ JxBrowser \ jxbrowser-chromium-43.0.2357.52.6.2 \ data \ Cache \ Chromium API根本不提供允许禁用缓存的功能,但它提供了允许清除缓存存储的功能。以下示例演示如何使用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(); } } ```