清除 Java 缓存

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25807055/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 08:43:49  来源:igfitidea点击:

Clear Java Cache

javacaching

提问by user2138639

I want to know how you can clear your Java Cache using Java Code or CMD Line code.

我想知道如何使用 Java 代码或 CMD 行代码清除 Java 缓存。

This should be done on a Microsoft Windows Machine anywhere from Windows 7 up.

这应该在 Windows 7 以上的任何地方的 Microsoft Windows 机器上完成。

This should be done on multiple computers so the file paths will be different.

这应该在多台计算机上完成,这样文件路径就会不同。

The application uses Javaw as it's default application that it launches with (Not to be confused with Javaws or Webstart - I already have code how to clear Javaws cache). So I will need to know how to clear Javaw cache.

该应用程序使用 Javaw 作为它启动时的默认应用程序(不要与 Javaws 或 Webstart 混淆 - 我已经有了如何清除 Javaws 缓存的代码)。所以我需要知道如何清除 Javaw 缓存。

回答by Ruchira Gayan Ranaweera

You can do it using Java Control Panel.

您可以使用Java 控制面板来完成

How do I clear the Java cache?

如何清除 Java 缓存?

How can do it in command line?

如何在命令行中做到这一点?

This will be the command to clear cache

这将是清除缓存的命令

javaws -clearcache // Remove all non-installed applications from the cache.

And

javaws -uninstall // Remove all applications from the cache.

回答by Reborn

This can be archived by following line: javaws -Xclearcache -silent -Xnosplash

这可以通过以下行存档: javaws -Xclearcache -silent -Xnosplash

回答by Stephen C

My understanding is that there are three mainstream Java caching technologies:

我的理解是,目前主流的Java缓存技术有以下三种:

  1. There is the Application Cache that is part of Java Webstart and associated browser plugins. This can be controlled using the javawscommand-line tool, or the Java Control Panel, as outlined in @RuchiraGayanRanaweera's answer.

    AFAIK, javawsis the onlysupported way to control the application cache from the command line.

  2. There is the Java Object Cache framework that is part of Oracle's J2EE container product line (aka OC4J). This is described in the OC4J documentation: "Chapter 9 - Java Object Cache". (I don't think this is what you are looking for.)

  3. Some JVM implementations have a feature that allows compiled classesto be cached and shared or reused by different JVMs. IBM Java and Eclipse OpenJ9 support this; e.g. see "Shared class cache".

    However, this is not a supported feature of standard (free) Oracle or OpenJDK Java. There is / was apparently an obscure JVM feature for sharing system class data that was introduced in Java 5, and a commercial feature exists (since Java 8) to extend this to application classes. Details are hard to find ...

  1. 应用程序缓存是 Java Webstart 和相关浏览器插件的一部分。这可以使用javaws命令行工具或 Java 控制面板进行控制,如@RuchiraGayanRanaweera 的回答中所述。

    AFAIK,javaws是从命令行控制应用程序缓存的唯一支持的方式。

  2. Java 对象缓存框架是 Oracle 的 J2EE 容器产品线(又名 OC4J)的一部分。这在 OC4J 文档中进行了描述:“第 9 章 - Java 对象缓存”。(我不认为这就是你要找的。)

  3. 一些 JVM 实现有一个特性,允许编译的类被不同的 JVM 缓存和共享或重用。IBM Java 和 Eclipse OpenJ9 支持这一点;例如,请参阅“共享类缓存”

    但是,这不是标准(免费)Oracle 或 OpenJDK Java 支持的功能。显然,Java 5 中引入了一个用于共享系统类数据的模糊 JVM 特性,并且存在一个商业特性(自 Java 8 起)以将其扩展到应用程序类。细节很难找...

UPDATE- As of Java 10, Oracle and OpenJDK JVMs now support "Class Data Sharing"(CDS). This document has instructions on how to regenerate the cache from the command line.

更新- 从 Java 10 开始,Oracle 和 OpenJDK JVM 现在支持“类数据共享”(CDS)。本文档包含有关如何从命令行重新生成缓存的说明。



Given the context in which the question was originally asked, I suspect that the OP is (was) actuallyasking about Java Webstart application caching, but didn't realize that this functionality is part of Java Webstart rather than Java SE as a whole.

鉴于最初提出问题的上下文,我怀疑 OP实际上是(正在)询问 Java Webstart 应用程序缓存,但没有意识到此功能是 Java Webstart 的一部分,而不是整个 Java SE。