不適用於舊版本的Java版本。它與Java小程序一起工作。以下是您如何爲JNLP啓用Java緩存的解決方案。您需要在代碼中調用一次JnlpResponseCache.init()以啓用它。
class JnlpResponseCache extends ResponseCache {
private final DownloadService service;
private JnlpResponseCache(){
try {
service = (DownloadService)ServiceManager.lookup("javax.jnlp.DownloadService");
} catch(UnavailableServiceException ex) {
throw new NoClassDefFoundError(ex.toString());
}
}
static void init(){
if(ResponseCache.getDefault() == null){
ResponseCache.setDefault(new JnlpResponseCache());
}
}
@Override
public CacheResponse get(URI uri, String rqstMethod, Map<String, List<String>> rqstHeaders) throws IOException {
return null;
}
@Override
public CacheRequest put(URI uri, URLConnection conn) throws IOException {
URL url = uri.toURL();
service.loadResource(url, null, service.getDefaultProgressWindow());
return null;
}
}