0
我有一個代理微服務從API讀取並返回一些過濾的輸出。我正在使用HttpsURLConnection(使用URLConnection中的方法)。如何使用URLConnection每小時刷新緩存?
String httpsURL = "https://myrestserver/path"+ id ;
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("myproxy", 8080));
URL myurl = new URL(httpsURL);
HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection(proxy);
con.setRequestMethod("GET");
con.setRequestProperty("Content-Type","application/json");
con.setRequestProperty("Authorization", authString);
con.setDoInput(true);
DataInputStream input = new DataInputStream(con.getInputStream());
result = new Scanner(input).useDelimiter("\\Z").next();
我想使用緩存來減少我的流量和延遲,但我想每小時更新一次。
我的問題是:如何使用URLConnection
每小時刷新一次緩存?
假設 - Java 7中
以上,在文檔閱讀,如果您再次打開連接並執行的getInputStream (),它會導致數據刷新。這與java.util.Timer相關聯可能是你需要的。我想念一些明顯的東西嗎? –
我不需要將定時器執行與客戶端調用微服務的時間結合起來嗎? – hawkeye