gpt4 book ai didi

java - JAVA应用程序如何清理缓存

转载 作者:可可西里 更新时间:2023-11-01 16:30:56 25 4
gpt4 key购买 nike

我已经使用 java.net 库制作了一个应用程序来捕获网页打开所花费的时间..示例代码

 HttpURLConnection conn = (HttpURLConnection)url.openConnection();
for(int i=0; i<20; i++ )
{
conn.disconnect();
conn.connect();
long starTime = System.currentTimeMillis();
JEditorPane editorPane = new JEditorPane();
editorPane.setPage(new URL());
long elasedTime = System.currentTimeMillis() - starTime;
System.out.println(elasedTime);
}

但是我遇到了一个问题,缓存!!如果我反复打开网页,那么在某些情况下它会显示 time=0 mills...这当然是不可能的,请任何人帮助我!!

最佳答案

setUseCaches(),继承自 URLConnection,应提供所需内容:

public void setUseCaches(boolean usecaches)Sets the value of the useCaches field of this URLConnection tothe specified value. Some protocols do caching of documents. Occasionally, it is important to beable to "tunnel through" and ignore the caches (e.g., the "reload" button ina browser). If the UseCaches flag on a connection is true, the connection isallowed to use whatever caches it can. If false, caches are to be ignored.The default value comes from DefaultUseCaches, which defaults to true. 

它必须在 connect() 之前调用。

关于java - JAVA应用程序如何清理缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10613648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com